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

Re-merged option to automatically MIP z-stacks sent to ilastik workflow

parent 9832ab04
No related branches found
No related tags found
No related merge requests found
......@@ -38,9 +38,12 @@ class GenericImageDataAccessor(ABC):
def is_mask(self):
return is_mask(self._data)
def get_one_channel_data (self, channel: int):
def get_one_channel_data (self, channel: int, mip: bool = False):
c = int(channel)
return InMemoryDataAccessor(self.data[:, :, c:(c+1), :])
if mip:
return InMemoryDataAccessor(self.data[:, :, c:(c+1), :].max(axis=-1))
else:
return InMemoryDataAccessor(self.data[:, :, c:(c+1), :])
@property
def pixel_scale_in_micrometers(self):
......@@ -101,7 +104,7 @@ class TifSingleSeriesFileAccessor(GenericImageFileAccessor):
tf = tifffile.TiffFile(fpath)
self.tf = tf
except Exception:
FileAccessorError(f'Unable to access data in {fpath}')
raise FileAccessorError(f'Unable to access data in {fpath}')
if len(tf.series) != 1:
raise DataShapeError(f'Expect only one series in {fpath}')
......
......@@ -48,7 +48,7 @@ def load_seg_to_obj_model(project_file: str, duplicate: bool = True) -> dict:
return load_ilastik_model(ilm.IlastikObjectClassifierFromSegmentationModel, project_file, duplicate=duplicate)
@router.put('/pixel_then_object_classification/infer')
def infer_px_then_ob_maps(px_model_id: str, ob_model_id: str, input_filename: str, channel: int = None) -> dict:
def infer_px_then_ob_maps(px_model_id: str, ob_model_id: str, input_filename: str, channel: int = None, mip: bool = False) -> dict:
inpath = session.paths['inbound_images'] / input_filename
validate_workflow_inputs([px_model_id, ob_model_id], [inpath])
try:
......@@ -57,7 +57,8 @@ def infer_px_then_ob_maps(px_model_id: str, ob_model_id: str, input_filename: st
session.models[px_model_id]['object'],
session.models[ob_model_id]['object'],
session.paths['outbound_images'],
channel=channel
channel=channel,
mip=mip,
)
except AssertionError:
raise HTTPException(f'Incompatible models {px_model_id} and/or {ob_model_id}')
......
......@@ -44,6 +44,16 @@ class TestCziImageFileAccess(unittest.TestCase):
sc = cf.get_one_channel_data(c)
self.assertEqual(sc.shape, (h, w, 1, nz))
def test_get_single_channel_mip_from_zstack(self):
w = 256
h = 512
nc = 4
nz = 11
c = 3
cf = InMemoryDataAccessor(np.random.rand(h, w, nc, nz))
sc = cf.get_one_channel_data(c, mip=True)
self.assertEqual(sc.shape, (h, w, 1, 1))
def test_write_single_channel_tif(self):
ch = 4
cf = CziImageFileAccessor(czifile['path'])
......
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