Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed mask resizing to match original image size #36

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/server/dcp_server/fsimagestorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def rescale_image(self, img, height, width, channel_ax=None, order=2):
rescale_factor = max_dim/512
return rescale(img, 1/rescale_factor, order=order, channel_axis=channel_ax)

def resize_image(self, img, height, width, order):
def resize_image(self, img, height, width, channel_ax=None, order=2):
"""resize image

:param img: image
Expand All @@ -161,8 +161,13 @@ def resize_image(self, img, height, width, order):
:type order: int
:return: resized image
:rtype: ndarray
"""
return resize(img, (height, width), order=order)
"""
if channel_ax is not None:
n_channel_dim = img.shape[channel_ax]
output_size = [height, width]
output_size.insert(channel_ax, n_channel_dim)
else: output_size = [height, width]
return resize(img, output_size, order=order)

def prepare_images_and_masks_for_training(self, train_img_mask_pairs):
"""Image and mask processing for training.
Expand Down
13 changes: 6 additions & 7 deletions src/server/dcp_server/segmentationclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ async def segment_image(self, input_path, list_of_images):
height, width, z_axis = self.imagestorage.get_image_size_properties(img, utils.get_file_extension(img_filepath))
img = self.imagestorage.rescale_image(img,
height,
width,
order=None)
width)
# Add channel ax into the model's evaluation parameters dictionary
self.model.eval_config['segmentor']['z_axis'] = z_axis
# Evaluate the model
mask = await self.runner.evaluate.async_run(img = img)
# Resize the mask
mask = self.imagestorage.rescale_image(mask,
height,
width,
self.model.eval_config['mask_channel_axis'],
order=0)
mask = self.imagestorage.resize_image(mask,
height,
width,
self.model.eval_config['mask_channel_axis'],
order=0)
# Save segmentation
seg_name = utils.get_path_stem(img_filepath) + setup_config['seg_name_string'] + '.tiff'
self.imagestorage.save_image(os.path.join(input_path, seg_name), mask)
Expand Down
Loading