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

Reorganzed ImageJ example to exist outside this codebase

parent 1de53e18
No related branches found
No related tags found
No related merge requests found
import os
import sys
from ij import IJ
from ij.plugin.filter import ParticleAnalyzer
from ij.plugin.frame import Recorder, RoiManager
sys.path.append(
os.path.join(
os.path.expanduser('~'), 'model_server', 'source', 'model_server', 'clients'
)
)
from imagej.adapter import run_request_sequence
import ilastik_map_objects_simple
from ij import IJ
params = {
'pixel_classifier_path': 'z:/pepperkok/rhodes/projects/proj0011-plankton-seg/exp0019/px-03.ilp',
'object_classifier_path': 'z:/pepperkok/rhodes/projects/proj0011-plankton-seg/exp0019/obj-07.ilp',
'debug': True,
'channel': 4, # zero-index
'object_class': 3
}
IJ.run('Remove Overlay')
imp_czi = IJ.getImage()
imp_obmap = run_request_sequence(
imp_czi,
ilastik_map_objects_simple.main,
params,
)
# transfer objects of specified class to image's overlay
imp_obmap.show()
IJ.run(imp_obmap, "glasbey on dark", "")
IJ.setThreshold(imp_obmap, params['object_class'], params['object_class'])
rm = RoiManager.getRoiManager()
Recorder.setBlackBackground()
imp_obmap.createThresholdMask()
rm.reset()
IJ.run(imp_obmap, "Analyze Particles...", "display exclude clear include add")
rm.run('Show All')
rm.moveRoisToOverlay(imp_czi)
if not params['debug']:
imp_obmap.close()
imp_czi.show()
\ No newline at end of file
from os.path import join, expanduser
# top-level directory <user>/model_server that contains codebase
root = join(expanduser('~'), 'model_server')
# USER: change this to look for ilastik models in some place other than <user>/model_server/ilastik
classifier_directory = join(root, 'ilastik')
# USER: set filenames and channels to build ilastik pipeline
params = {
'pixel_classifier': 'px-03.ilp',
'object_classifier': 'obj-07.ilp',
'debug': True,
'channel': 4, # zero-index
'object_class': 3
}
# load ImageJ API then Jython dependencies that are maintained in model_server codebase
import sys
from ij import IJ
from ij.plugin.frame import Recorder, RoiManager
sys.path.append(join(root, 'source', 'model_server', 'clients'))
from imagej.adapter import run_request_sequence
import ilastik_map_objects_simple
# call the server to run ilastik analysis
params['pixel_classifier_path'] = join(classifier_directory, params['pixel_classifier'])
params['object_classifier_path'] = join(classifier_directory, params['object_classifier'])
IJ.run('Remove Overlay')
imp_czi = IJ.getImage()
imp_obmap = run_request_sequence(
imp_czi,
ilastik_map_objects_simple.main,
params,
)
# transfer objects of specified class to image's overlay
imp_obmap.show()
IJ.run(imp_obmap, "glasbey on dark", "")
IJ.setThreshold(imp_obmap, params['object_class'], params['object_class'])
rm = RoiManager.getRoiManager()
Recorder.setBlackBackground()
imp_obmap.createThresholdMask()
rm.reset()
IJ.run(imp_obmap, "Analyze Particles...", "display exclude clear include add")
rm.run('Show All')
rm.moveRoisToOverlay(imp_czi)
if not params['debug']:
imp_obmap.close()
imp_czi.show()
\ 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