Skip to content

Commit

Permalink
fix bug in downsampling function where if no padding was added the re…
Browse files Browse the repository at this point in the history
…sulting segmented image was empty
  • Loading branch information
Sophia Maedler committed Oct 26, 2023
1 parent 9cffaa1 commit 20d593d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/sparcscore/pipeline/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,14 +956,26 @@ def _finalize_segmentation_results(self, size_padding):
cyto_seg = dilation(cyto_seg, footprint=disk(self.config["smoothing_kernel_size"]))

#combine masks into one stack
segmentation = np.stack([nuc_seg, cyto_seg]).astype("uint32")
segmentation = np.stack([nuc_seg, cyto_seg]).astype(np.uint32)
del cyto_seg, nuc_seg

#rescale segmentation results to original size
x_trim = x - channels.shape[1]
y_trim = y - channels.shape[2]
print(segmentation.shape)

#if no padding was performed then we need to keep the same dimensions
if x_trim > 0:
if y_trim > 0:
segmentation = segmentation[:, :-x_trim, :-y_trim]
else:
segmentation = segmentation[:, :-x_trim, :]
else:
if y_trim > 0:
segmentation = segmentation[:, :, :-y_trim]
else:
segmentation = segmentation

segmentation = segmentation[:, :-x_trim, :-y_trim]
print(segmentation.shape)

self.log(f"Segmentation size after resize to original dimensions: {segmentation.shape}")
Expand Down

0 comments on commit 20d593d

Please sign in to comment.