Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
myosoft-imcf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
imcf
myosoft-imcf
Commits
9c2ad26f
Commit
9c2ad26f
authored
1 month ago
by
Laurent Guerard
Browse files
Options
Downloads
Patches
Plain Diff
Formatting and correction
parent
f1996747
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
2c_fibertyping.py
+66
-55
66 additions, 55 deletions
2c_fibertyping.py
with
66 additions
and
55 deletions
2c_fibertyping.py
+
66
−
55
View file @
9c2ad26f
# @ String (visibility=MESSAGE, value="<html><b> Welcome to Myosoft! </b></html>") msg1
# @ String (visibility=MESSAGE, value="<html><b> Welcome to Myosoft! </b></html>") msg1
# @ File (label="Select fiber-ROIs zip-file", style="file") roi_zip
# @ File (label="Select fiber-ROIs zip-file", style="file") roi_zip
# @ File (label="Select image file", description="select your image") path_to_image
# @ File (label="Select image file", description="select your image") path_to_image
#@ File (label="Select directory for output", style="directory") output_dir
#
@ File (label="Select directory for output", style="directory") output_dir
#@ Boolean (label="close image after processing", description="tick this box when using batch mode", value=False) close_raw
#
@ Boolean (label="close image after processing", description="tick this box when using batch mode", value=False) close_raw
#@ String (visibility=MESSAGE, value="<html><b> channel positions in the hyperstack </b></html>") msg5
#
@ String (visibility=MESSAGE, value="<html><b> channel positions in the hyperstack </b></html>") msg5
#@ Integer (label="Fiber staining 1 channel number (0=n.a.)", style="slider", min=0, max=5, value=1) fiber_channel_1
#
@ Integer (label="Fiber staining 1 channel number (0=n.a.)", style="slider", min=0, max=5, value=1) fiber_channel_1
#@ Integer (label="Fiber staining 2 channel number (0=n.a.)", style="slider", min=0, max=5, value=2) fiber_channel_2
#
@ Integer (label="Fiber staining 2 channel number (0=n.a.)", style="slider", min=0, max=5, value=2) fiber_channel_2
#@ Integer (label="Fiber staining 3 channel number (0=n.a.)", style="slider", min=0, max=5, value=3) fiber_channel_3
#
@ Integer (label="Fiber staining 3 channel number (0=n.a.)", style="slider", min=0, max=5, value=3) fiber_channel_3
#@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_1
#
@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_1
#@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_2
#
@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_2
#@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_3
#
@ Integer (label="minimum fiber intensity (0=auto)", description="0 = automatic threshold detection", value=0) min_fiber_intensity_3
# @ ResultsTable rt
# @ ResultsTable rt
# @ RoiManager rm
# @ RoiManager rm
...
@@ -50,7 +50,7 @@ def get_threshold_from_method(imp, channel, method):
...
@@ -50,7 +50,7 @@ def get_threshold_from_method(imp, channel, method):
A list containing the upper and the lower threshold (integer values).
A list containing the upper and the lower threshold (integer values).
"""
"""
# Set the channel of the imp to the desired channel
# Set the channel of the imp to the desired channel
imp
.
setC
(
channel
)
# starts at 1
imp
.
setC
(
channel
)
# starts at 1
# Get the processor of the imp
# Get the processor of the imp
ip
=
imp
.
getProcessor
()
ip
=
imp
.
getProcessor
()
# Set the AutoThreshold method to the desired method
# Set the AutoThreshold method to the desired method
...
@@ -159,28 +159,35 @@ if __name__ == "__main__":
...
@@ -159,28 +159,35 @@ if __name__ == "__main__":
roimanager
.
load_rois_from_zip
(
rm
,
input_rois_path
)
roimanager
.
load_rois_from_zip
(
rm
,
input_rois_path
)
roimanager
.
change_roi_color
(
rm
,
"
blue
"
)
roimanager
.
change_roi_color
(
rm
,
"
blue
"
)
# update the log for the user
# update the log for the user
IJ
.
log
(
"
Now working on
"
+
str
(
raw_image_title
)
)
IJ
.
log
(
"
Now working on
"
+
str
(
raw_image_title
))
if
raw_image_calibration
.
scaled
()
==
False
:
if
not
raw_image_calibration
.
scaled
():
IJ
.
log
(
"
Your image is not spatially calibrated! Size measurements are only possible in [px].
"
)
IJ
.
log
(
IJ
.
log
(
"
-- settings used --
"
)
"
Your image is not spatially calibrated! Size measurements are only possible in [px].
"
IJ
.
log
(
"
Selected fiber-ROIs zip-file =
"
+
str
(
input_rois_path
)
)
)
IJ
.
log
(
"
Fiber staining 1 channel number =
"
+
str
(
fiber_channel_1
)
)
IJ
.
log
(
"
-- settings used --
"
)
IJ
.
log
(
"
Fiber staining 2 channel number =
"
+
str
(
fiber_channel_2
)
)
IJ
.
log
(
"
Selected fiber-ROIs zip-file =
"
+
str
(
input_rois_path
))
IJ
.
log
(
"
Fiber staining 3 channel number =
"
+
str
(
fiber_channel_3
)
)
IJ
.
log
(
"
Fiber staining 1 channel number =
"
+
str
(
fiber_channel_1
))
IJ
.
log
(
"
-- settings used --
"
)
IJ
.
log
(
"
Fiber staining 2 channel number =
"
+
str
(
fiber_channel_2
))
IJ
.
log
(
"
Fiber staining 3 channel number =
"
+
str
(
fiber_channel_3
))
# measure size & shape,
IJ
.
log
(
"
-- settings used --
"
)
IJ
.
run
(
"
Set Measurements...
"
,
"
area perimeter shape feret
'
s redirect=None decimal=4
"
)
IJ
.
run
(
"
Clear Results
"
,
""
)
# measure size & shape,
measure_in_all_rois
(
raw
,
fiber_channel_1
,
rm
)
IJ
.
run
(
"
Set Measurements...
"
,
"
area perimeter shape feret
'
s redirect=None decimal=4
"
)
IJ
.
run
(
"
Clear Results
"
,
""
)
roimanager
.
measure_in_all_rois
(
raw
,
fiber_channel_1
,
rm
)
roimanager
.
measure_in_all_rois
(
raw
,
fiber_channel_1
,
rm
)
# loop through the fiber channels, check if positive, add info to results table
# loop through the fiber channels, check if positive, add info to results table
all_fiber_channels
=
[
fiber_channel_1
,
fiber_channel_2
,
fiber_channel_3
]
all_fiber_channels
=
[
fiber_channel_1
,
fiber_channel_2
,
fiber_channel_3
]
all_min_fiber_intensities
=
[
min_fiber_intensity_1
,
min_fiber_intensity_2
,
min_fiber_intensity_3
]
all_min_fiber_intensities
=
[
roi_colors
=
[
"
green
"
,
"
orange
"
,
"
red
"
]
min_fiber_intensity_1
,
all_fiber_subsets
=
[
[],
[],
[]
]
min_fiber_intensity_2
,
min_fiber_intensity_3
,
]
roi_colors
=
[
"
green
"
,
"
orange
"
,
"
red
"
]
all_fiber_subsets
=
[[],
[],
[]]
for
index
,
fiber_channel
in
enumerate
(
all_fiber_channels
):
for
index
,
fiber_channel
in
enumerate
(
all_fiber_channels
):
if
fiber_channel
>
0
:
if
fiber_channel
>
0
:
...
@@ -242,24 +249,28 @@ all_fiber_subsets =[ [], [], [] ]
...
@@ -242,24 +249,28 @@ all_fiber_subsets =[ [], [], [] ]
"
YES
"
,
"
YES
"
,
)
)
# single positive
# single positive
positive_c1
=
all_fiber_subsets
[
0
]
positive_c1
=
all_fiber_subsets
[
0
]
positive_c2
=
all_fiber_subsets
[
1
]
positive_c2
=
all_fiber_subsets
[
1
]
positive_c3
=
all_fiber_subsets
[
2
]
positive_c3
=
all_fiber_subsets
[
2
]
# double positive
# double positive
positive_c1_c2
=
list
(
set
(
all_fiber_subsets
[
0
]).
intersection
(
all_fiber_subsets
[
1
])
)
positive_c1_c2
=
list
(
set
(
all_fiber_subsets
[
0
]).
intersection
(
all_fiber_subsets
[
1
]))
positive_c1_c3
=
list
(
set
(
all_fiber_subsets
[
0
]).
intersection
(
all_fiber_subsets
[
2
])
)
positive_c1_c3
=
list
(
set
(
all_fiber_subsets
[
0
]).
intersection
(
all_fiber_subsets
[
2
]))
positive_c2_c3
=
list
(
set
(
all_fiber_subsets
[
1
]).
intersection
(
all_fiber_subsets
[
2
])
)
positive_c2_c3
=
list
(
set
(
all_fiber_subsets
[
1
]).
intersection
(
all_fiber_subsets
[
2
]))
# triple positive
# triple positive
positive_c1_c2_c3
=
list
(
set
(
positive_c1_c2
).
intersection
(
all_fiber_subsets
[
2
])
)
positive_c1_c2_c3
=
list
(
set
(
positive_c1_c2
).
intersection
(
all_fiber_subsets
[
2
]))
# update ROI color & results table for double and triple positives
# update ROI color & results table for double and triple positives
channels
=
[
channels
=
[
(
positive_c1_c2
,
[
fiber_channel_1
,
fiber_channel_2
],
"
magenta
"
),
(
positive_c1_c2
,
[
fiber_channel_1
,
fiber_channel_2
],
"
magenta
"
),
(
positive_c1_c3
,
[
fiber_channel_1
,
fiber_channel_3
],
"
yellow
"
),
(
positive_c1_c3
,
[
fiber_channel_1
,
fiber_channel_3
],
"
yellow
"
),
(
positive_c2_c3
,
[
fiber_channel_2
,
fiber_channel_3
],
"
cyan
"
),
(
positive_c2_c3
,
[
fiber_channel_2
,
fiber_channel_3
],
"
cyan
"
),
(
positive_c1_c2_c3
,
[
fiber_channel_1
,
fiber_channel_2
,
fiber_channel_3
],
"
white
"
)
(
]
positive_c1_c2_c3
,
[
fiber_channel_1
,
fiber_channel_2
,
fiber_channel_3
],
"
white
"
,
),
]
for
positives
,
ch_nums
,
color
in
channels
:
for
positives
,
ch_nums
,
color
in
channels
:
if
positives
:
if
positives
:
...
@@ -289,13 +300,13 @@ channels = [
...
@@ -289,13 +300,13 @@ channels = [
# dress up the original image, save a overlay-png, present original to the user
# dress up the original image, save a overlay-png, present original to the user
raw
.
show
()
raw
.
show
()
roimanager
.
show_all_rois_on_image
(
rm
,
raw
)
roimanager
.
show_all_rois_on_image
(
rm
,
raw
)
# raw.setDisplayMode(IJ.COMPOSITE)
# raw.setDisplayMode(IJ.COMPOSITE)
enhance_contrast
(
raw
)
enhance_contrast
(
raw
)
IJ
.
run
(
"
From ROI Manager
"
,
""
)
# ROIs -> overlays so they show up in the saved png
IJ
.
run
(
"
From ROI Manager
"
,
""
)
# ROIs -> overlays so they show up in the saved png
qc_duplicate
=
raw
.
duplicate
()
qc_duplicate
=
raw
.
duplicate
()
IJ
.
saveAs
(
qc_duplicate
,
"
PNG
"
,
output_dir
+
"
/
"
+
raw_image_title
+
"
_fibertyping
"
)
IJ
.
saveAs
(
qc_duplicate
,
"
PNG
"
,
output_dir
+
"
/
"
+
raw_image_title
+
"
_fibertyping
"
)
qc_duplicate
.
close
()
qc_duplicate
.
close
()
wm
.
toFront
(
raw
.
getWindow
()
)
wm
.
toFront
(
raw
.
getWindow
())
IJ
.
log
(
IJ
.
log
(
"
Script finished. Total runtime [HH:MM:SS.ss]:
"
"
Script finished. Total runtime [HH:MM:SS.ss]:
"
...
...
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