From 877f6a94f9726806e458d2ea7f85af6df2d07f0e Mon Sep 17 00:00:00 2001 From: Pariksheet Nanda Date: Thu, 18 May 2017 17:08:15 -0400 Subject: [PATCH] ENH: Read image and ROI stacks in ImageJ --- src/imagej_open.ijm | 82 +++++++++++++++++++++++++++++++++++++++++++++ src/imagej_open.py | 55 ------------------------------ 2 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 src/imagej_open.ijm delete mode 100644 src/imagej_open.py diff --git a/src/imagej_open.ijm b/src/imagej_open.ijm new file mode 100644 index 0000000..468d365 --- /dev/null +++ b/src/imagej_open.ijm @@ -0,0 +1,82 @@ +// @UIService ui +// @File(label="Raw images directory", description="Images path", style="directory", value="/share/Pariksheet/consultations/rnai-screen-tf/results/z_projection") path +// @String(label="Plate name", choices={"160415_015529-V", "501B102", "502B98", "503B99", "507B99"}) plate +// @String(label="Well", value="C03") well +// @File(label="ROI nucleus images directory", description="Images path", style="directory", value="/share/Pariksheet/consultations/rnai-screen-tf/results/cellprofiler/nuc") path_nuc +// @File(label="ROI centromere images directory", description="Images path", style="directory", value="/share/Pariksheet/consultations/rnai-screen-tf/results/cellprofiler/cen") path_cen +// @File(label="ROI ectopic centromere images directory", description="Images path", style="directory", value="/share/Pariksheet/consultations/rnai-screen-tf/results/cellprofiler/ect") path_ect +// @File(label="ROI overlap images directory", description="Images path", style="directory", value="/share/Pariksheet/consultations/rnai-screen-tf/results/cellprofiler/ect_overlap") path_ect_overlap +// @OUTPUT Dataset image + +/* + * Open multiple TIFF files as hyperstack and overlay ROIs. + */ + +// Use batch mode for speed and protecting user settings. +setBatchMode(true); +// Clear all ROIs. +if (roiManager("count") > 0) { + roiManager("deselect") + roiManager("delete") +} + +/** Open hyperstack of the well */ +function imOpen(path, plate, well) { + run("Image Sequence...", + " open=" + path + + " file=" + plate + "_" + well + + " sort"); + run("Stack to Hyperstack...", + " order=xyctz" + + " channels=3" + + " slices=1" + + " frames=" + nSlices / 3 + + " display=Composite") + Stack.setChannel(1); + run("Blue"); + Stack.setChannel(2); + run("Red"); + Stack.setChannel(3); + run("Green"); +} +//imOpen(path, plate, well); + +/** Import ROIs generated by CellProfiler */ +function roiOpen(path, plate, well, color) { + run("Image Sequence...", + " open=" + path + + " file=" + plate + "_" + well + + " sort"); + getMinAndMax(im_min, im_max); + im_list = getList("image.titles"); + orig = im_list[lengthOf(im_list) - 1]; + roi_min = roiManager("count"); + // Iterate through all the images to add the ROIs to the ROI manager. + for (i = 1; i < 3; i++) {//im_max; i++) { + selectWindow(orig); + run("Duplicate...", "duplicate"); + setThreshold(i, i); + run("Convert to Mask", "method=Default background=Dark"); + run("Analyze Particles...", "add stack"); + close(); + } + roi_max = roiManager("count") - 1; + // If any new ROIs were added, set an appropriate color. + if (roi_max + 1 > roi_min) { + roi_ids = newArray(); + for (i = roi_min; i <= roi_max; i++) + roi_ids = Array.concat(roi_ids, i); + roiManager("select", roi_ids); + roiManager("Set Color", color); + } +} + +roiOpen(path_nuc, plate, well, "blue"); +roiOpen(path_cen, plate, well, "green"); +roiOpen(path_ect, plate, well, "red"); + +// Only show ROIS in current slice. +roiManager("Associate", "true"); +roiManager("Show All"); + +setBatchMode(false); diff --git a/src/imagej_open.py b/src/imagej_open.py deleted file mode 100644 index 9c41b69..0000000 --- a/src/imagej_open.py +++ /dev/null @@ -1,55 +0,0 @@ -# @DatasetIOService ds -# @UIService ui -# @File(label="Raw images directory", description="Images path", style="directory", value="/share/Pariksheet/consultations/rnai-screen-tf/results/z_projection") path -# @String(label="Plate name", choices={"160415_015529-V", "501B102", "502B98", "503B99", "507B99"}) plate -# @String(label="Well", value="C03") well -# @OUTPUT Dataset image - -# It looks like the only "ImageJ2" way of opening a single-TIFF -# image series is using the big data viewer: -# http://forum.imagej.net/t/wrap-imageplus-virtualstack-into-imglib2/4154/10 -# The big data viewer VirtualStackImageLoader requires an ImagePlus as input. - -# Open the image stack and convert to hyperstack -import glob -import os.path - -files = glob.glob(os.path.join(str(path), "{}_{}*".format(plate, well))) -files.sort() -# There doesn't seem to be a trivial way to read multiple files. -#ims = [ds.open(filename) for filename in files] -#print(type(ims[0])) -from io.scif.config import SCIFIOConfig -from io.scif.img import ImgOpener -#from io.scif import SCIFIO -import net.imagej.ImageJ as ij - -config = ( - SCIFIOConfig() - .groupableSetGroupFiles(True) -) -im = ds.open(files[0], config) -print(im) -#ds = ij.scifio()#.datasetIO().open(files[0], config); -#im = ImgOpener().openImg(files[0], config) -#print(dir(im)) -#print(im.metadata.getImageCount()) - -#scifio = SCIFIO() -#reader = scifio.initializer().initializeReader(files[0]) -#print(reader.getMetadata().getImageCount()) - -#from ij import IJ, WindowManager -#IJ.run("Image Sequence...", -# "open={path} file={pattern} sort".format( -# path=path, pattern="{}_{}".format(plate, well))) -#im = WindowManager.getCurrentImage() -#IJ.run("Stack to Hyperstack...", -# "order=xyctz channels=3 slices=1 frames={frames} display=Composite".format( -# frames=im.getNSlices() / 3)) -#IJ.Stack.setActiveChannels("011"); -#IJ.run("Blue"); -#IJ.Stack.setActiveChannels("101"); -#IJ.run("Red"); -#IJ.Stack.setActiveChannels("110"); -#IJ.run("Green");