From 1b20330e54e2e1cc7e88d4ffc2bca5d73f0a2bb6 Mon Sep 17 00:00:00 2001 From: Pariksheet Nanda Date: Thu, 18 May 2017 13:42:38 -0400 Subject: [PATCH] ENH: Try using Python instead of Groovy --- src/imagej_open.groovy | 54 ----------------------------------------- src/imagej_open.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 54 deletions(-) delete mode 100644 src/imagej_open.groovy create mode 100644 src/imagej_open.py diff --git a/src/imagej_open.groovy b/src/imagej_open.groovy deleted file mode 100644 index f5c09e4..0000000 --- a/src/imagej_open.groovy +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Overlay CellProfiler ROIs. - * - * Uses ImageJ2 libraries whereever possible. - */ - -import groovy.io.FileType // Recurse directories per http://stackoverflow.com/a/3954639 -//import ij.io.Opener -//import io.scif.SCIFIO - -import ij.plugin.FolderOpener - -import io.scif.img.ImgOpener - -import net.imglib2.img.display.imagej.ImageJFunctions - -/** Path to project Git repo */ -def prefix_project = "/share/Pariksheet/consultations/rnai-screen-tf" - -/** - * Read a stack of raw images. - * - * @param plate name of the plate to match - * @param well name of the well in [A-P][01-24] format - */ -def open = { String plate, String well -> - def opener = new FolderOpener() - opener.run() - - // Build a list of the relevant image files. - def dirBg = new File( "${prefix_project}/results/z_projection" ) - def files = [] - dirBg.eachFileMatch( FileType.FILES, ~/${plate}_${well}_.+/ ) { - files << it.name - } - paths = files.collect { "${dirBg}/${it}" } - - //def imp = new Opener().openImage("${prefix}") - - // Open the images as a stack per the scifio tutorial - // https://github.com/scifio/scifio-tutorials - //def scifio = new SCIFIO() - //def reader = scifio.initializer().initializeReader(paths[0]) - //reader.getClass().getMethods().each {println it} - - // Open using imglib2 ImgOpener() as described in wiki examples - // http://imagej.net/ImgLib2_Examples - def imgOpener = new ImgOpener() - def im = imgOpener.openImg( paths[0] ) - //ImageJFunctions.show( im ) - //println im -} - -open("160415_015529-V", "C03") diff --git a/src/imagej_open.py b/src/imagej_open.py new file mode 100644 index 0000000..9c41b69 --- /dev/null +++ b/src/imagej_open.py @@ -0,0 +1,55 @@ +# @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");