Skip to content
Snippets Groups Projects
Commit a2c2fa51 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Corrected translational error in mask file output

parent f8295af0
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ def _write_patch_to_file(where, fname, data):
def export_patch_masks_from_zstack(
where: Path,
stack: GenericImageDataAccessor,
zmask_meta: list,
pad_to: int = 256,
prefix='mask',
......@@ -64,15 +65,26 @@ def export_patch_masks_from_zstack(
exported = []
for mi in zmask_meta:
obj = mi['info']
mask = np.expand_dims(mi['mask'], (2, 3))
sl = mi['slice']
rbb = mi['relative_bounding_box']
x0 = rbb['x0']
y0 = rbb['y0']
x1 = rbb['x1']
y1 = rbb['y1']
sp_sl = np.s_[y0: y1, x0: x1, :, :]
h, w = stack.data[sl].shape[0:2]
patch = np.zeros((h, w, 1, 1), dtype='uint8')
patch[sp_sl][:, :, 0, 0] = mi['mask'] * 255
if pad_to:
mask = pad(mask, pad_to)
patch = pad(patch, pad_to)
ext = 'png'
fname = f'{prefix}-la{obj.label:04d}-zi{obj.zi:04d}.{ext}'
mask8bit = 255 * mask.astype('uint8')
_write_patch_to_file(where, fname, mask8bit)
_write_patch_to_file(where, fname, patch)
exported.append(fname)
return exported
......
......@@ -5,7 +5,7 @@ import numpy as np
from conf.testing import output_path
from extensions.chaeo.conf.testing import multichannel_zstack, pixel_classifier, pipeline_params
from extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack
from extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack, export_patch_masks_from_zstack
from extensions.chaeo.zmask import build_zmask_from_object_mask
from model_server.accessors import generate_file_accessor, InMemoryDataAccessor, write_accessor_data_to_file
from extensions.ilastik.models import IlastikObjectClassifierModel, IlastikPixelClassifierModel
......@@ -164,4 +164,16 @@ class TestZStackDerivedDataProducts(unittest.TestCase):
contour_channel=1,
overlay_gain=(0.1, 1.0, 1.0)
)
self.assertGreaterEqual(len(files), 1)
def test_make_binary_masks_from_zmask(self):
zmask, meta = self.test_zmask_makes_correct_boxes(
filters={'area': (1e3, 1e4)},
expand_box_by=(128, 2)
)
files = export_patch_masks_from_zstack(
output_path / '2d_mask_patches',
InMemoryDataAccessor(self.stack.data),
meta,
)
self.assertGreaterEqual(len(files), 1)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment