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

ilastik functional checks passed; confirmed accurate image outputs

parent 4d369c51
No related branches found
No related tags found
No related merge requests found
from pathlib import Path
root = Path('c:/Users/rhodes/projects/proj0015-model-server/resources')
filename = 'Selection--W0000--P0001-T0001.czi'
filename = 'D3-selection-01.czi'
czifile = {
'filename': filename,
'path': root / 'testdata' / filename,
'w': 1024,
'h': 1024,
'c': 4,
'w': 1274,
'h': 1274,
'c': 5,
'z': 1,
}
ilastik = {
'pixel_classifier': root / 'testdata' / 'pix02.ilp',
'object_classifier': root / 'testdata' / 'obj01.ilp',
'pixel_classifier': root / 'testdata' / 'ilastik' / 'demo_px.ilp',
'object_classifier': root / 'testdata' / 'ilastik' / 'demo_obj.ilp',
}
output_path = root / 'testing_output'
......
......@@ -23,8 +23,6 @@ class IlastikImageToImageModel(ImageToImageModel):
# self.operator = None
super().__init__(autoload, params)
def __del__(self):
self.shell.closeCurrentProject()
def load(self):
os.environ["LAZYFLOW_THREADS"] = "8"
......@@ -39,18 +37,10 @@ class IlastikImageToImageModel(ImageToImageModel):
raise ParameterExpectedError(
f'Ilastik project file {self.project_file} does not describe an instance of {shell.workflow.__class__}'
)
# self.operator = self.get_top_level_operator(shell.workflow)
self.shell = shell
return True
# @staticmethod
# def get_top_level_operator(workflow):
# if isinstance(workflow, PixelClassificationWorkflow):
# return workflow.pcApplet.topLevelOperator
# elif isinstance(workflow, ObjectClassificationWorkflow):
# return workflow.objectClassificationApplet.topLevelOperator
class IlastikPixelClassifierModel(IlastikImageToImageModel):
workflow = PixelClassificationWorkflow
......
......@@ -77,7 +77,7 @@ class CziImageFileAccessor(GenericImageFileAccessor):
raise FileAccessorError(f'Unable to access CZI data in {fpath}')
sd = {ch: cf.shape[cf.axes.index(ch)] for ch in cf.axes}
if sd['S'] > 1 or sd['T'] > 1:
if (sd.get('S') and (sd['S'] > 1)) or (sd.get('T') and (sd['T'] > 1)):
raise DataShapeError(f'Cannot handle image with multiple positions or time points: {sd}')
idx = {k: sd[k] for k in ['X', 'Y', 'C', 'Z']}
......
......@@ -34,7 +34,7 @@ def infer_image_to_image(fpi, model, where_output, **kwargs) -> dict:
# TODO: assert outdata format
# write output to file
outpath = where_output / (fpi.stem + '.tif')
outpath = where_output / (model.model_id + '_' + fpi.stem + '.tif')
write_accessor_data_to_file(outpath, outdata)
dt_fo = time() - t0
......
......@@ -10,8 +10,6 @@ class TestIlastikPixelClassification(unittest.TestCase):
def setUp(self) -> None:
self.cf = CziImageFileAccessor(czifile['path'])
# def tearDown(self) -> None:
# pass
def test_faulthandler(self): # recreate error that is messing up ilastik
import io
......@@ -43,7 +41,7 @@ class TestIlastikPixelClassification(unittest.TestCase):
self.assertEqual(pxmap.shape, (w, h, 2, 1))
def test_run_pixel_classifier(self):
channel = 2
channel = 0
model = IlastikPixelClassifierModel({'project_file': ilastik['pixel_classifier']})
cf = CziImageFileAccessor(czifile['path'])
mono_image = cf.get_one_channel_data(channel)
......@@ -65,6 +63,19 @@ class TestIlastikPixelClassification(unittest.TestCase):
)
)
self.mono_image = mono_image
self.pxmap = pxmap
def test_run_object_classifier(self):
self.test_run_pixel_classifier()
fp = czifile['path']
model = IlastikObjectClassifierModel({'project_file': ilastik['object_classifier']})
objmap, _ = model.infer(self.mono_image, self.pxmap)
self.assertTrue(
write_accessor_data_to_file(
output_path / f'obmap_{fp.stem}.tif',
objmap,
)
)
self.assertEqual(objmap.data.max(), 3)
......@@ -20,9 +20,9 @@ class TestCziImageFileAccess(unittest.TestCase):
self.assertEqual(cf.shape[1], czifile['w'])
def test_write_single_channel_tif(self):
ch = 2
ch = 4
cf = CziImageFileAccessor(czifile['path'])
mono = cf.get_one_channel_data(2)
mono = cf.get_one_channel_data(ch)
self.assertTrue(
write_accessor_data_to_file(
output_path / f'{cf.fpath.stem}_ch{ch}.tif',
......
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