Skip to content

Commit

Permalink
Merge pull request #29 from chanzuckerberg/uermel/semantic_mask_scale…
Browse files Browse the repository at this point in the history
…_fix

Fix downscaling and data type of segmentation masks
  • Loading branch information
uermel authored Mar 20, 2024
2 parents 6b62d96 + 16a46a9 commit 13b09cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ingestion_tools/scripts/common/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self, fs: FileSystemApi, mrc_filename: str, label: int = 1):
self.label = label

def make_pyramid(self, max_layers: int = 2, scale_z_axis: bool = True) -> List[np.ndarray]:
pyramid = [(self.data == self.label).astype(np.float32)]
pyramid = [(self.data == self.label).astype(np.int8)]
# Then make a pyramid of 100/50/25 percent scale volumes
for i in range(max_layers):
z_scale = 1
Expand All @@ -148,7 +148,7 @@ def make_pyramid(self, max_layers: int = 2, scale_z_axis: bool = True) -> List[n

# For semantic segmentation masks we want to have a binary output.
# downscale_local_mean will return float array even for bool input with non-binary values
scaled = (downscale_local_mean(pyramid[i] == self.label, (z_scale, 2, 2)) > 0).astype(np.float32)
scaled = (downscale_local_mean(pyramid[i], (z_scale, 2, 2)) > 0).astype(np.int8)
pyramid.append(scaled)

return pyramid
Expand Down

0 comments on commit 13b09cb

Please sign in to comment.