Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • imcf/myosoft-imcf
1 result
Show changes
Commits on Source (7)
......@@ -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)
......