Skip to content

Commit

Permalink
Implemented background filling with user-specified value
Browse files Browse the repository at this point in the history
  • Loading branch information
Stian Johnsen committed Apr 11, 2019
1 parent 7ba1dbc commit ed63210
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion niftynet/application/regression_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def initialise_grid_aggregator(self):
output_path=self.action_param.save_seg_dir,
window_border=self.action_param.border,
interp_order=self.action_param.output_interp_order,
postfix=self.action_param.output_postfix)
postfix=self.action_param.output_postfix,
fill_constant=self.action_param.fill_constant)

def initialise_resize_aggregator(self):
self.output_decoder = ResizeSamplesAggregator(
Expand Down
3 changes: 2 additions & 1 deletion niftynet/application/segmentation_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def initialise_grid_aggregator(self):
output_path=self.action_param.save_seg_dir,
window_border=self.action_param.border,
interp_order=self.action_param.output_interp_order,
postfix=self.action_param.output_postfix)
postfix=self.action_param.output_postfix,
fill_constant=self.action_param.fill_constant)

def initialise_resize_aggregator(self):
self.output_decoder = ResizeSamplesAggregator(
Expand Down
8 changes: 7 additions & 1 deletion niftynet/engine/windows_aggregator_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ def __init__(self,
output_path=os.path.join('.', 'output'),
window_border=(),
interp_order=0,
postfix='_niftynet_out'):
postfix='_niftynet_out',
fill_constant=0.0):
ImageWindowsAggregator.__init__(
self, image_reader=image_reader, output_path=output_path)
self.name = name
self.image_out = None
self.window_border = window_border
self.output_interp_order = interp_order
self.postfix = postfix
self.fill_constant = fill_constant

def decode_batch(self, window, location):
n_samples = location.shape[0]
Expand Down Expand Up @@ -68,6 +70,10 @@ def _initialise_empty_image(self, image_id, n_channels, dtype=np.float):
for layer in self.reader.preprocessors:
if isinstance(layer, PadLayer):
empty_image, _ = layer(empty_image)

if self.fill_constant != 0.0:
empty_image[:] = self.fill_constant

return empty_image

def _save_current_image(self):
Expand Down
6 changes: 6 additions & 0 deletions niftynet/utilities/user_parameters_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def add_inference_args(parser):
type=spatialnumarray,
default=(0, 0, 0))

parser.add_argument(
"--fill-constant",
help="Output fill value used fill borders of output images.",
type=float,
default=0.0)

return parser


Expand Down

0 comments on commit ed63210

Please sign in to comment.