Login  Register

Re: Batch channel splitter

Posted by Jeff Spector-2 on Sep 11, 2014; 8:02pm
URL: http://imagej.273.s1.nabble.com/Batch-channel-splitter-tp5009575p5009593.html

On Thu, Sep 11, 2014 at 2:15 PM, csadangi <[hidden email]> wrote:

> Hi Jeff,
>
> I got the following code. Can you tell me what all to delete just to get
> the
> green and red channel. I want one code for green and one for red. And is
> this a java or a python language.
>
> dir=getDirectory("Choose a Directory");
> print(dir);
> splitDir=dir + "\Split\\";
> print(splitDir);
> File.makeDirectory(splitDir);
> list = getFileList(dir);
>
> for (i=0; i<list.length; i++) {
>      if (endsWith(list[i], ".tif")){
>                print(i + ": " + dir+list[i]);
>              open(dir+list[i]);
>              imgName=getTitle();
>          baseNameEnd=indexOf(imgName, ".tif");
>          baseName=substring(imgName, 0, baseNameEnd);
>
>          run("Split Channels");
>          selectWindow(imgName + " (blue)");
>          rename(baseName + "-blue.tiff");
>          saveAs("Tiff", splitDir+baseName + "-blue.tif");
>          close();
>          selectWindow(imgName + " (green)");
>          saveAs("Tiff", splitDir+baseName + "-green.tif");
>          close();
>          selectWindow(imgName + " (red)");
>          saveAs("Tiff", splitDir+baseName + "-red.tif");
>
>          run("Close All");
>      }
> }
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009583.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


This is imageJ macro language. There are many good examples and it is worth
taking some time to look through them. I'm not sure what your goal is, and
the "example" code above is different that what I suggested (using imageIDs
to get the different channels) but I am guessing that you don't want to
save the blue image, so try deleting

     rename(baseName + "-blue.tiff");
         saveAs("Tiff", splitDir+baseName + "-blue.tif");

and see where you can go from there..
-Jeff

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html