Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SVLT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ALMF
SVLT
Commits
20662b5c
Commit
20662b5c
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Started editing in ImageJ script editor
parent
a0b7809f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
clients/imagej/client.py
+1
-1
1 addition, 1 deletion
clients/imagej/client.py
clients/imagej/example.py
+50
-42
50 additions, 42 deletions
clients/imagej/example.py
clients/imagej/ilastik_obmaps.py
+121
-0
121 additions, 0 deletions
clients/imagej/ilastik_obmaps.py
with
172 additions
and
43 deletions
clients/imagej/client.py
+
1
−
1
View file @
20662b5c
...
...
@@ -6,7 +6,7 @@ import sys
print
(
sys
.
version
)
HOST
=
'
127.0.0.1
'
PORT
=
800
1
PORT
=
800
0
uri
=
'
http://{}:{}/
'
.
format
(
HOST
,
PORT
)
def
hit_endpoint
(
method
,
endpoint
,
params
=
None
,
verbose
=
False
):
...
...
This diff is collapsed.
Click to expand it.
clients/imagej/example.py
+
50
−
42
View file @
20662b5c
# 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
#)
...
...
This diff is collapsed.
Click to expand it.
clients/imagej/
zstack_to_
ilastik.py
→
clients/imagej/ilastik
_obmaps
.py
+
121
−
0
View file @
20662b5c
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment