diff --git a/clients/imagej/example.py b/clients/imagej/example.py index 41b3468d45ac8915a33289ad4de7d0d7cc32e1c5..669ec1e26529a85e9938a8e0159695ee2fc4c12f 100644 --- a/clients/imagej/example.py +++ b/clients/imagej/example.py @@ -1,9 +1,15 @@ # example top-level script in ImageJ + +# +# add scripts dir to python path +# from clients.imagej.zstack_to_ilastik import get_object_map from ij import IJ + + CHANNEL_TO_ILASTIK = 1 # i.e. index of color channel from confocal stack CHANNEL_CHLOROPHYL = 4 OBJECT_CLASS_FOR_PHOTOACTIVATION = 1 @@ -13,12 +19,12 @@ PIXEL_CLASSIFIER_PATH = "D:/DATA/TREC_STOP_15_Kristineberg/Vincent/230805_automi OBJECT_CLASSIFIER_PATH = "D:/DATA/TREC_STOP_15_Kristineberg/Vincent/230805_automic_AI_PA/ilastik/obj.ilp" DEBUG = True -HOST = '127.0.0.1' -PORT = 8001 -uri = 'http://{}:{}/'.format(HOST, PORT) +# HOST = '127.0.0.1' +# PORT = 8001 +# uri = 'http://{}:{}/'.format(HOST, PORT) abspath = IJ.getImage().getProp('Location') -input_filename = os.path.split(abspath)[-1] +# input_filename = os.path.split(abspath)[-1] channel = 0 pixel_classifier = 'demo_px.ilp' diff --git a/clients/imagej/zstack_to_ilastik.py b/clients/imagej/zstack_to_ilastik.py index 2c7bbf82203bd45539c555a4bcfcbb80620d21e8..f8cd73a8fed66483ceae1b3396b6b4261603d8ea 100644 --- a/clients/imagej/zstack_to_ilastik.py +++ b/clients/imagej/zstack_to_ilastik.py @@ -1,62 +1,82 @@ +from pathlib import Path + from clients.imagej.client import hit_endpoint from ij import IJ +from ij import ImagePlus -def setup(pixel_classifier, object_classifier, input_path): +def get_object_map(imp, px_ilp, ob_ilp, pxmap_threshold, pxmap_foreground_channel, segmentation_channel, patches_channel, zmask_filters): """ :param pixel_classifier: (str) :param object_classifier: (str) - :return: + :return: ImagePlus """ - result = [] - # configure input path - no endpoint yet + # get info from input ImagePlus + abspath = Path(imp.getProp('Location')) + image_directory = abspath.parent + input_filename = abspath.name - # configure output path - no endpoint yet + # configure input and output paths + resp = hit_endpoint( + 'PUT', + '/paths/watch_input', + { + 'path': image_directory, + } + ) + assert resp.status_code == 200, 'Error setting up image directory' + resp = hit_endpoint( + 'PUT', + '/paths/watch_output', + { + 'path': image_directory, + } + ) + assert resp.status_code == 200, 'Error setting up image directory' - # load pixel classifier first time only + # load pixel classifier resp = hit_endpoint( 'PUT', - '/models/ilastik/pixel_classification/load/', + '/ilastik/pixel_classification/load/', { - 'project_file': pixel_classifier, + 'project_file': px_ilp, 'duplicate': False, }, ) - result['pxmid'] = resp['model_id'] + assert resp.status_code == 200, 'Error loading pixel classifier: ' + {px_ilp} + id_px_mod = resp['model_id'] + # load pixel classifier first time only resp = hit_endpoint( - 'PUT', '/models/ilastik/object_classification/load/', + 'PUT', '/ilastik/object_classification/load/', { - 'project_file': object_classifier, + 'project_file': ob_ilp, 'duplicate': False, }, ) - result['obmid'] = resp['model_id'] - resp = hit_endpoint('GET', '/models', verbose=True) - return result + assert resp.status_code == 200, 'Error loading object classifier: ' + {ob_ilp} + id_ob_mod = resp['model_id'] -def get_object_map(pixel_classifier, object_classifier, input_path, input_filename, channel): - """ + return id_px_mod, id_ob_mod - :param pixel_classifier: (str) - :param object_classifier: (str) - :return: - """ - # eventually split this off - ids = setup(pixel_classifier, object_classifier, input_path) + # run inference resp = hit_endpoint( 'PUT', '/chaeo/classify_zstack/infer', { - 'px_model_id': ids['pxmid'] - 'ob_model_id': ids['obmid'], + 'px_model_id': id_px_mod + 'ob_model_id': id_ob_mod, 'input_filename': input_filename, - 'channel': channel + 'pxmap_threshold': pxmap_threshold, + 'pxmap_foreground_channel': pxmap_foreground_channel, + 'segmentation_channel': segmentation_channel, + 'patches_channel': patches_channel, + 'zmask_filters': zmask_filters, } ) - imp = + assert resp.status_code == 200, 'Error calling workfow' return IJ.ImagePlus() \ No newline at end of file