Skip to content
Snippets Groups Projects
Commit dfbae559 authored by Laurent Guerard's avatar Laurent Guerard
Browse files

Merge branch 'dev'

parents 609f9f24 a70b76b6
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ import sys ...@@ -47,7 +47,7 @@ import sys
# python imports # python imports
import time import time
from ch.epfl.biop.ij2command import Labels2CompositeRois from ch.epfl.biop.ij2command import Labels2Rois
# TrackMate imports # TrackMate imports
from fiji.plugin.trackmate import Logger, Model, Settings, TrackMate from fiji.plugin.trackmate import Logger, Model, Settings, TrackMate
...@@ -743,21 +743,25 @@ if __name__ == "__main__": ...@@ -743,21 +743,25 @@ if __name__ == "__main__":
# image (pre)processing and segmentation (-> ROIs)# imp, firstC, lastC, firstZ, # image (pre)processing and segmentation (-> ROIs)# imp, firstC, lastC, firstZ,
# lastZ, firstT, lastT # lastZ, firstT, lastT
misc.timed_log("Getting the membrane channel")
membrane = Duplicator().run( membrane = Duplicator().run(
raw, membrane_channel, membrane_channel, 1, 1, 1, 1 raw, membrane_channel, membrane_channel, 1, 1, 1, 1
) )
if (membrane.getWidth() * membrane.getHeight()) > 100000: while (membrane.getWidth() * membrane.getHeight()) > 100000000:
misc.timed_log("Image is too large, resizing to speed up processing") misc.timed_log("Image is too large, resizing to speed up processing")
membrane = membrane.resize( membrane = membrane.resize(
membrane.getWidth() / 2, membrane.getWidth() / 2,
membrane.getHeight() / 2, membrane.getHeight() / 2,
"none", "none",
) )
misc.timed_log("Pre processing the image for segmentation")
imp_bgd_corrected = do_background_correction(membrane) imp_bgd_corrected = do_background_correction(membrane)
IJ.run("Conversions...", "scale") IJ.run("Conversions...", "scale")
IJ.run(imp_bgd_corrected, "16-bit", "") IJ.run(imp_bgd_corrected, "16-bit", "")
misc.timed_log("Running the segmentation")
imp_result = run_tm( imp_result = run_tm(
imp_bgd_corrected, imp_bgd_corrected,
1, 1,
...@@ -769,25 +773,31 @@ if __name__ == "__main__": ...@@ -769,25 +773,31 @@ if __name__ == "__main__":
perimeter_thresh=[minPer, maxPer], perimeter_thresh=[minPer, maxPer],
) )
misc.timed_log("Resizing the segmentation results (if needed)")
imp_result = imp_result.resize( imp_result = imp_result.resize(
raw.getWidth(), raw.getWidth(),
raw.getHeight(), raw.getHeight(),
"none", "none",
) )
misc.timed_log("Saving the segmentation results")
IJ.saveAs( IJ.saveAs(
imp_result, imp_result,
"Tiff", "Tiff",
os.path.join( os.path.join(
output_dir, output_dir,
raw_image_title + "_" + str(serie_index) + "_all_fibers_binary", raw_image_title + "_" + str(serie_index) + "_all_fibers_labels",
), ),
) )
command.run(Labels2CompositeRois, True, "rm", rm, "imp", imp_result).get() misc.timed_log("Getting the ROIs")
command.run(Labels2Rois, True, "rm", rm, "imp", imp_result).get()
misc.timed_log("Enlarging and renumbering the ROIs")
enlarge_all_rois(enlarge_radius, rm, raw_image_calibration.pixelWidth) enlarge_all_rois(enlarge_radius, rm, raw_image_calibration.pixelWidth)
renumber_rois(rm) renumber_rois(rm)
misc.timed_log("Saving the ROIs")
save_all_rois( save_all_rois(
rm, rm,
os.path.join( os.path.join(
...@@ -798,11 +808,12 @@ if __name__ == "__main__": ...@@ -798,11 +808,12 @@ if __name__ == "__main__":
# check for positive fibers # check for positive fibers
if fiber_channel > 0: if fiber_channel > 0:
misc.timed_log("Checking for positive fibers")
if min_fiber_intensity == 0: if min_fiber_intensity == 0:
min_fiber_intensity = get_threshold_from_method( min_fiber_intensity = get_threshold_from_method(
raw, fiber_channel, "Mean" raw, fiber_channel, "Mean"
)[0] )[0]
IJ.log("automatic intensity threshold detection: True") misc.timed_log("automatic intensity threshold detection: True")
IJ.log("fiber intensity threshold: " + str(min_fiber_intensity)) IJ.log("fiber intensity threshold: " + str(min_fiber_intensity))
change_all_roi_color(rm, "blue") change_all_roi_color(rm, "blue")
...@@ -810,6 +821,7 @@ if __name__ == "__main__": ...@@ -810,6 +821,7 @@ if __name__ == "__main__":
raw, fiber_channel, rm, min_fiber_intensity raw, fiber_channel, rm, min_fiber_intensity
) )
change_subset_roi_color(rm, positive_fibers, "magenta") change_subset_roi_color(rm, positive_fibers, "magenta")
misc.timed_log("Saving positive fibers")
save_selected_rois( save_selected_rois(
rm, rm,
positive_fibers, positive_fibers,
...@@ -823,6 +835,7 @@ if __name__ == "__main__": ...@@ -823,6 +835,7 @@ if __name__ == "__main__":
) )
# measure size & shape, save # measure size & shape, save
misc.timed_log("Measuring the ROIs")
IJ.run( IJ.run(
"Set Measurements...", "Set Measurements...",
"area perimeter shape feret's redirect=None decimal=4", "area perimeter shape feret's redirect=None decimal=4",
...@@ -841,6 +854,7 @@ if __name__ == "__main__": ...@@ -841,6 +854,7 @@ if __name__ == "__main__":
add_results(rt, "MHC Positive Fibers (magenta)", positive_fibers, "YES") add_results(rt, "MHC Positive Fibers (magenta)", positive_fibers, "YES")
# print(rt.size()) # print(rt.size())
misc.timed_log("Saving the measurements")
rt.save( rt.save(
os.path.join( os.path.join(
output_dir, output_dir,
...@@ -851,7 +865,11 @@ if __name__ == "__main__": ...@@ -851,7 +865,11 @@ if __name__ == "__main__":
) )
) )
# print("saved the all_fibers_results.csv") # print("saved the all_fibers_results.csv")
# 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
misc.timed_log(
"Improve the contrast and show the results to save an overlay image"
)
rm.show() rm.show()
raw.show() raw.show()
show_all_rois_on_image(rm, raw) show_all_rois_on_image(rm, raw)
...@@ -877,6 +895,7 @@ if __name__ == "__main__": ...@@ -877,6 +895,7 @@ if __name__ == "__main__":
raw.setDisplayMode(IJ.GRAYSCALE) raw.setDisplayMode(IJ.GRAYSCALE)
show_all_rois_on_image(rm, raw) show_all_rois_on_image(rm, raw)
misc.timed_log("Save log")
IJ.selectWindow("Log") IJ.selectWindow("Log")
IJ.saveAs( IJ.saveAs(
"Text", "Text",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment