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

Still drafting ImageJ-side client

parent 9a2a8a5c
No related branches found
No related tags found
No related merge requests found
# 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'
......
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
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