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
Compare revisions
c32ebcbe8c9ecc5ebcbf3f980c4694ecaa2c5568 to 811cdd7425ba30df15c2bba0efb331f293900063
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
imcf/myosoft-imcf
Select target project
No results found
811cdd7425ba30df15c2bba0efb331f293900063
Select Git revision
Swap
Target
imcf/myosoft-imcf
Select target project
imcf/myosoft-imcf
1 result
c32ebcbe8c9ecc5ebcbf3f980c4694ecaa2c5568
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (7)
Add function to convert ijrois to labelimage
· d8310623
Kai Schleicher
authored
1 week ago
d8310623
Get path to ij roiset from GUI
· 005655c7
Kai Schleicher
authored
1 week ago
005655c7
Create Labelimage from ij roiset
· f6b804c8
Kai Schleicher
authored
1 week ago
f6b804c8
Don't use z-slice option, input is a MIP
· 9a094bcc
Kai Schleicher
authored
1 week ago
9a094bcc
Remove sum projection as data is a 2D MIP
· 106d690d
Kai Schleicher
authored
1 week ago
106d690d
Do not show intermediate image
· db261db2
Kai Schleicher
authored
1 week ago
db261db2
Precises comment
· 811cdd74
Kai Schleicher
authored
1 week ago
811cdd74
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
2d_spots_in_fibers.py
+43
-12
43 additions, 12 deletions
2d_spots_in_fibers.py
with
43 additions
and
12 deletions
2d_spots_in_fibers.py
View file @
811cdd74
...
...
@@ -2,7 +2,7 @@
#@ CommandService command
#@ File (label="select image", description="select your input image", style=file) path_to_image
#@ Integer (label="select image file series", description="leave 1 if not needed", value=1, min=1, max=20, stepSize=1, persist=false, style=slider) series_number
#@
Integer
(label="Fiber Segmentation", description="select the Fiber Segmentation RoiSet .zip file") fiber_segmentation_roiset
#@
File
(label="Fiber Segmentation", description="select the Fiber Segmentation RoiSet .zip file"
, style=file
) fiber_segmentation_roiset
#@ Integer (label="DAPI channel", description="select the DAPI channel", min=1, max=20, stepSize=1, persist=true, style=slider) dapi_channel_number
#@ Integer (label="DAPI threshold", description="0 = Auto", min=0) threshold
#@ String (label="processing channels", description="comma separated list of channels, e.g. 2,3,6,7", value="1,2,3,4") processing_channels_string
...
...
@@ -36,7 +36,7 @@ from net.imglib2.roi import Regions
from
net.imglib2.roi.labeling
import
LabelRegions
from
net.imglib2.algorithm.labeling
import
ConnectedComponents
# BIOP imports
from
ch.epfl.biop.ij2command
import
Labels2Rois
from
ch.epfl.biop.ij2command
import
Labels2Rois
,
Rois2Labels
# python imports
import
os
...
...
@@ -707,6 +707,33 @@ def save_labelimage_as_ijroiset(label_imp, filename, suffix, target):
rm
.
reset
()
def
load_rois_from_zip
(
path
):
"""
Load ROIs from the given zip file and add them to the RoiManager.
Parameters
----------
path : string
Path to the ROI zip file.
"""
rm
=
RoiManager
.
getInstance
()
if
not
rm
:
rm
=
RoiManager
()
rm
.
reset
()
rm
.
runCommand
(
"
Open
"
,
path
)
def
convert_rois_to_labelimage
(
imp
):
rm
=
RoiManager
.
getInstance
()
if
not
rm
:
rm
=
RoiManager
()
label_imp
=
command
.
run
(
Rois2Labels
,
False
,
'
imp
'
,
imp
,
'
rm
'
,
rm
).
get
().
getOutput
(
"
label_imp
"
)
rm
.
reset
()
# TODO: should be optional but can be default
return
label_imp
def
close_images
(
list_of_imps
):
"""
Close given ImagePlus images
...
...
@@ -721,6 +748,7 @@ def close_images(list_of_imps):
path_to_image
=
str
(
path_to_image
).
replace
(
"
\\
"
,
"
/
"
)
fiber_segmentation_roiset
=
str
(
fiber_segmentation_roiset
).
replace
(
"
\\
"
,
"
/
"
)
parent_dir
,
filename
,
ext
=
get_parentdir_filename_ext_from_path
(
path_to_image
)
write_bf_memoryfile
(
path_to_image
)
n_channels
,
image_width
,
image_height
,
bit_depth
=
get_ome_metadata
(
path_to_image
,
series_number
)
...
...
@@ -729,10 +757,14 @@ processing_channels = processing_channels_string.split(",")
quality_thresholds_string
=
quality_thresholds_string
.
replace
(
"
"
,
""
)
quality_thresholds
=
quality_thresholds_string
.
split
(
"
,
"
)
# TODO: Get the fiber segmentation and convert to labelimage
# Get the fiber segmentation from ij roizip and convert to labelimage
canvas
=
create_empty_image
(
32
,
image_width
,
image_height
)
load_rois_from_zip
(
fiber_segmentation_roiset
)
fibers_label_imp
=
convert_rois_to_labelimage
(
canvas
)
canvas
.
close
()
# threshold DAPI channel and convert to binary
dapi_channel
=
BFopen_image
(
path_to_image
,
dapi_channel_number
,
series_number
,
z_slice_number
=
dapi_channel_zslice
)
dapi_channel
=
BFopen_image
(
path_to_image
,
dapi_channel_number
,
series_number
)
if
threshold
<=
0
:
threshold
=
get_threshold_from_method
(
dapi_channel
,
"
otsu
"
)
dapi_binary
=
convert_to_binary
(
dapi_channel
,
threshold
)
...
...
@@ -743,16 +775,15 @@ results_table = ResultsTable()
for
index
,
channel
in
enumerate
(
processing_channels
):
channel
=
int
(
channel
)
quality_threshold
=
float
(
quality_thresholds
[
index
])
spots_channel
=
BFopen_image
(
path_to_image
,
channel
,
series_number
)
# can be a stack
spots_label_imp
=
run_trackmate_dog_spot_detector
(
spots_channel
,
quality_threshold
)
# spot detection is 3D
spots_channel
=
BFopen_image
(
path_to_image
,
channel
,
series_number
)
spots_label_imp
=
run_trackmate_dog_spot_detector
(
spots_channel
,
quality_threshold
)
save_image_as_IJtif
(
spots_label_imp
,
filename
,
"
spots_ch
"
+
str
(
channel
),
parent_dir
)
save_labelimage_as_ijroiset
(
spots_label_imp
,
filename
,
"
spots_ch
"
+
str
(
channel
),
parent_dir
)
spots_binary_imp
=
convert_labelimage_to_binary
(
spots_label_imp
)
# can be a stack
spots_binary_imp_sum_proj
=
ZProjector
.
run
(
spots_binary_imp
,
"
sum
"
)
# if 2 (n) spots perfecly overlap in z, the pixel value will be 2 (n)
dapi_positive_spots_binary
=
ImageCalculator
.
run
(
spots_binary_imp_sum_proj
,
dapi_binary
,
"
Multiply create
"
)
dapi_negative_spots_binary
=
ImageCalculator
.
run
(
spots_binary_imp_sum_proj
,
dapi_positive_spots_binary
,
"
Subtract create
"
)
spots_binary_imp
=
convert_labelimage_to_binary
(
spots_label_imp
)
dapi_positive_spots_binary
=
ImageCalculator
.
run
(
spots_binary_imp
,
dapi_binary
,
"
Multiply create
"
)
dapi_negative_spots_binary
=
ImageCalculator
.
run
(
spots_binary_imp
,
dapi_positive_spots_binary
,
"
Subtract create
"
)
n_spots_per_fiber
=
measure_intensity_sum
(
fibers_label_imp
,
spots_binary_imp
_sum_proj
)
n_spots_per_fiber
=
measure_intensity_sum
(
fibers_label_imp
,
spots_binary_imp
)
n_dapi_positive_spots_per_fiber
=
measure_intensity_sum
(
fibers_label_imp
,
dapi_positive_spots_binary
)
n_dapi_negative_spots_per_fiber
=
measure_intensity_sum
(
fibers_label_imp
,
dapi_negative_spots_binary
)
...
...
@@ -761,7 +792,7 @@ for index, channel in enumerate(processing_channels):
add_results_to_resultstable
(
results_table
,
"
n spots channel
"
+
str
(
channel
),
n_spots_per_fiber
[
1
])
add_results_to_resultstable
(
results_table
,
"
n spots dapi positive channel
"
+
str
(
channel
),
n_dapi_positive_spots_per_fiber
[
1
])
add_results_to_resultstable
(
results_table
,
"
n spots dapi negative channel
"
+
str
(
channel
),
n_dapi_negative_spots_per_fiber
[
1
])
close_images
([
spots_channel
,
spots_label_imp
,
spots_binary_imp
,
spots_binary_imp
_sum_proj
,
dapi_binary
,
dapi_positive_spots_binary
,
dapi_negative_spots_binary
])
close_images
([
spots_channel
,
spots_label_imp
,
spots_binary_imp
,
spots_binary_imp
,
dapi_binary
,
dapi_positive_spots_binary
,
dapi_negative_spots_binary
])
results_table
.
show
(
"
Spots
"
)
save_results_table
(
results_table
,
filename
,
"
Spots
"
,
parent_dir
)
...
...
This diff is collapsed.
Click to expand it.