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

Started editing in ImageJ script editor

parent a0b7809f
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ import sys
print(sys.version)
HOST = '127.0.0.1'
PORT = 8001
PORT = 8000
uri = 'http://{}:{}/'.format(HOST, PORT)
def hit_endpoint(method, endpoint, params=None, verbose=False):
......
# example top-level script in ImageJ
#
# add scripts dir to python path
#
from clients.imagej.zstack_to_ilastik import get_object_map
import os
import sys
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
CHLOROPHYL_THRESHOLD = 0.000 # minimum percent of ROI that should contain chlorophyl
ILASTIK_PATH = "C:/Program Files/ilastik-1.4.0/ilastik.exe"
PIXEL_CLASSIFIER_PATH = "D:/DATA/TREC_STOP_15_Kristineberg/Vincent/230805_automic_AI_PA/ilastik/pix.ilp"
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)
abspath = IJ.getImage().getProp('Location')
# input_filename = os.path.split(abspath)[-1]
channel = 0
pixel_classifier = 'demo_px.ilp'
object_classifier = 'demo_ob.ilp'
outpath = 'C:\\Users\\rhodes\\projects\\proj0015-model-server\\resources\\testdata'
get_object_map(...)
# pipeline: remove any existing overlay
IJ.run("Remove Overlay")
imp_czi = IJ.getImage()
czi_fn = imp_czi.getTitle()
czi_desc = czi_fn.split('.')[0]
imp_czi.setDisplayMode(IJ.GRAYSCALE)
IJ.run("Make Subset...", "channels=" + CHANNEL_TO_ILASTIK)
imp_to_ilastik = IJ.getImage()
# add directory of current script to search path
scripts_dir = os.path.dirname(sys.argv[0])
sys.path.append(scripts_dir)
from ilastik_obmaps import ilastik_map_objects_simple
CHANNEL_TO_ILASTIK = 1 # i.e. index of color channel from confocal stack
OBJECT_CLASS_FOR_PHOTOACTIVATION = 1
ROOT = 'c:/Users/rhodes/projects/proj0004-marine-photoactivation/data/exp0021/'
PIXEL_CLASSIFIER_PATH = ROOT + 'ilastik/px-01.ilp'
OBJECT_CLASSIFIER_PATH = ROOT + 'ilastik/obj-04.ilp'
DEBUG = True
#obmap = ilastik_map_objects_simple(
# IJ.getImage(),
# PIXEL_CLASSIFIER_PATH,
# OBJECT_CLASSIFIER_PATH,
# CHANNEL_TO_ILASTIK
#)
# pipeline: remove any existing overlay
IJ.run("Remove Overlay")
resp = hit_endpoint(
'GET',
'/ilastik/pixel_then_object_classification/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': basename(abspath),
'channel': channel,
}
)
imp_czi = IJ.getImage()
#czi_fn = imp_czi.getTitle()
#czi_desc = czi_fn.split('.')[0]
#imp_czi.setDisplayMode(IJ.GRAYSCALE)
IJ.run("Make Subset...", "channels=" + str(CHANNEL_TO_ILASTIK))
imp_to_ilastik = IJ.getImage()
#obmap = ilastik_map_objects_simple(
# imp_to_ilastik,
# PIXEL_CLASSIFIER_PATH,
# OBJECT_CLASSIFIER_PATH,
# CHANNEL_TO_ILASTIK
#)
......
from pathlib import Path
from clients.imagej.client import hit_endpoint
from client import hit_endpoint
from os.path import basename, dirname
from ij import IJ
from ij import ImagePlus
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: ImagePlus
"""
# get info from input ImagePlus
abspath = Path(imp.getProp('Location'))
image_directory = abspath.parent
input_filename = abspath.name
def setup(where, px_ilp):
# configure input and output paths
resp = hit_endpoint(
'PUT',
'/paths/watch_input',
{
'path': image_directory,
'path': where,
}
)
assert resp.status_code == 200, 'Error setting up image directory'
......@@ -30,7 +18,7 @@ def get_object_map(imp, px_ilp, ob_ilp, pxmap_threshold, pxmap_foreground_channe
'PUT',
'/paths/watch_output',
{
'path': image_directory,
'path': where,
}
)
assert resp.status_code == 200, 'Error setting up image directory'
......@@ -45,12 +33,25 @@ def get_object_map(imp, px_ilp, ob_ilp, pxmap_threshold, pxmap_foreground_channe
},
)
assert resp.status_code == 200, 'Error loading pixel classifier: ' + {px_ilp}
id_px_mod = resp['model_id']
return resp['model_id']
def ilastik_map_objects_simple(imp, px_ilp, ob_ilp, channel):
"""
:param pixel_classifier: (str)
:param object_classifier: (str)
:return: ImagePlus
"""
# get info from input ImagePlus
abspath = imp.getProp('Location')
# load pixel classifier first time only
# assert imp is not z-stack
id_px_mod = setup(dirname(abspath), px_ilp)
# load object classifier
resp = hit_endpoint(
'PUT', '/ilastik/object_classification/load/',
'PUT', '/ilastik/pxmap_to_obj/load/',
{
'project_file': ob_ilp,
'duplicate': False,
......@@ -59,17 +60,54 @@ def get_object_map(imp, px_ilp, ob_ilp, pxmap_threshold, pxmap_foreground_channe
assert resp.status_code == 200, 'Error loading object classifier: ' + {ob_ilp}
id_ob_mod = resp['model_id']
return id_px_mod, id_ob_mod
# run inference
resp = hit_endpoint(
'PUT',
'/ilastik/pixel_then_object_classification/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': basename(abspath),
'channel': channel,
}
)
assert resp.status_code == 200, 'Error calling workfow'
obmap = resp.json()['object_map_filepath']
return obmap # obviously need imp
def ilastik_map_objects_with_zmask(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: ImagePlus
"""
# get info from input ImagePlus
abspath = imp.getProp('Location')
# assert imp is not z-stack
id_px_mod = setup(dirname(abspath), px_ilp)
# load object classifier
resp = hit_endpoint(
'PUT', '/ilastik/seg_to_obj/load/',
{
'project_file': ob_ilp,
'duplicate': False,
},
)
assert resp.status_code == 200, 'Error loading object classifier: ' + {ob_ilp}
id_ob_mod = resp['model_id']
# run inference
resp = hit_endpoint(
'PUT',
'/chaeo/classify_zstack/infer',
{
'px_model_id': id_px_mod
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': input_filename,
'input_filename': basename(abspath),
'pxmap_threshold': pxmap_threshold,
'pxmap_foreground_channel': pxmap_foreground_channel,
'segmentation_channel': segmentation_channel,
......@@ -78,5 +116,6 @@ def get_object_map(imp, px_ilp, ob_ilp, pxmap_threshold, pxmap_foreground_channe
}
)
assert resp.status_code == 200, 'Error calling workfow'
obmap = resp.json()['output_path']
return IJ.ImagePlus()
\ No newline at end of file
return obmap # obviously need imp
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