Batch channel splitter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Batch channel splitter

csadangi
Does anyone know how to split channels in a batch for multiple images using ImageJ?

Also how to select only a particular channel for batch conversion? For ex: converting multiple RGB TIFF images to green channel only?

Lastly, how can i change the default save from .TIFF to .JPEG. When i press CTRL+S after taking a screenshot my images are stored as .TIFF and i want to save the images as .JPEG.

Thanks :)
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

Mark Hiner
>Does anyone know how to split channels in a batch for multiple images
using ImageJ?

Batch processing is a pretty common question, so I wrote a wiki page
explaining your options: http://imagej.net/Batch_Processing

The split channels command (macro code: run("Split Channels"); ) produces
output images for each channel, so you would want to use the batch
processing template <http://imagej.net/Batch_Processing#Flexible_option>,
and only write out the image(s) corresponding to your desired channel(s).

>Lastly, how can i change the default save from .TIFF to .JPEG

CTRL+S ends up calling the File Saver#save()
<https://github.com/imagej/ImageJA/blob/master/src/main/java/ij/io/FileSaver.java#L37-39>
method, which always writes TIFFs it looks like. However, there is a Save
as JPEG... command under Plugins>Macros, with a default hotkey of "j" as
well as the File>Save As>Jpeg... option, either of which can be used in
your final batch macro to write out JPEGs.

Hope that helps,
Mark

On Thu, Sep 11, 2014 at 10:54 AM, csadangi <[hidden email]> wrote:

> Does anyone know how to split channels in a batch for multiple images using
> ImageJ?
>
> Also how to select only a particular channel for batch conversion? For ex:
> converting multiple RGB TIFF images to green channel only?
>
> Lastly, how can i change the default save from .TIFF to .JPEG. When i press
> CTRL+S after taking a screenshot my images are stored as .TIFF and i want
> to
> save the images as .JPEG.
>
> Thanks :)
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

csadangi
Hi Mark,

Thanks for the tips :)

Image saving to JPEG format works fine but is there any way we can change it from TIFF to JPEG.

I am not aware of how to edit the macro. Could you help?
I understood this --- go to process --- batch --- macro, then i set up the input and output folders and the desired format. I want the conversion to green and red channels only. How can i do that?

Thanks a lot for your help :)
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

Jeff Spector-2
In reply to this post by csadangi
On Thu, Sep 11, 2014 at 11:54 AM, csadangi <[hidden email]> wrote:

> Does anyone know how to split channels in a batch for multiple images using
> ImageJ?
>
> Also how to select only a particular channel for batch conversion? For ex:
> converting multiple RGB TIFF images to green channel only?
>
> Lastly, how can i change the default save from .TIFF to .JPEG. When i press
> CTRL+S after taking a screenshot my images are stored as .TIFF and i want
> to
> save the images as .JPEG.
>
> Thanks :)
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


Hi,
 You can split the channels and then select the channel you want using the
imageID.  A Macro that looks something like this

run("Split Channels"); //split the channels
blue = getImageID(); // get id of blue image
red = blue+1 ; //assign ids
green = blue + 2; //assign ids


should get you the individual channels.
then you can use selectImage(ImageID) to get the channel you want..


selectImage(green);

and then save it..


hope this helps...
-Jeff

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

csadangi
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");
     }
}
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

ctrueden
In reply to this post by Jeff Spector-2
Hi Chinmaya,

> I am not aware of how to edit the macro. Could you help?

Your exact question has been asked and answered before; maybe this thread
in the archives helps you. It has a fully formed macro you could adapt to
your purposes.

https://list.nih.gov/cgi-bin/wa.exe?A2=IMAGEJ;cdc7ef1a.1008

Regards,
Curtis

On Thu, Sep 11, 2014 at 12:39 PM, Jeff Spector <[hidden email]> wrote:

> On Thu, Sep 11, 2014 at 11:54 AM, csadangi <[hidden email]> wrote:
>
> > Does anyone know how to split channels in a batch for multiple images
> using
> > ImageJ?
> >
> > Also how to select only a particular channel for batch conversion? For
> ex:
> > converting multiple RGB TIFF images to green channel only?
> >
> > Lastly, how can i change the default save from .TIFF to .JPEG. When i
> press
> > CTRL+S after taking a screenshot my images are stored as .TIFF and i want
> > to
> > save the images as .JPEG.
> >
> > Thanks :)
> >
> >
> >
> > --
> > View this message in context:
> > http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575.html
> > Sent from the ImageJ mailing list archive at Nabble.com.
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
>
> Hi,
>  You can split the channels and then select the channel you want using the
> imageID.  A Macro that looks something like this
>
> run("Split Channels"); //split the channels
> blue = getImageID(); // get id of blue image
> red = blue+1 ; //assign ids
> green = blue + 2; //assign ids
>
>
> should get you the individual channels.
> then you can use selectImage(ImageID) to get the channel you want..
>
>
> selectImage(green);
>
> and then save it..
>
>
> hope this helps...
> -Jeff
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

Herbie-4
In reply to this post by csadangi
No name,

the code is neither written in java, nor python but in the ImageJ-macro
language that is documented here
        <http://rsb.info.nih.gov/ij/developer/macro/macros.html>
there
        <http://fiji.sc/Introduction_into_Macro_Programming>
and there
        <http://rsb.info.nih.gov/ij/developer/macro/functions.html>
and maybe many other places.

HTH

Herbie

::::::::::::::::::::::::::::::::::
On 11.09.14 20:15, csadangi 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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

csadangi
In reply to this post by ctrueden
Hi Curtis,

That was helpful. I think i can save them in .JPEG format by substituting .TIFF with .JPEG?
But it again gives me all the 3 channels and i need only 1. So how can i do that? Also, now it doesn't tell me which one is blue, green or red.

Any help would be highly appreciated
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

Cammer, Michael
Example syntax:

saveAs("Jpeg", "J:\\Smith_Lab_20140911\\Isabelle\\20140911_Liver_GFP\\temp.jpg");

===========================================================================
Michael Cammer, Microscopy Core & Skirball Institute, NYU Langone Medical Center
Cell:  914-309-3270   note that we do not receive messages left at 212-263-3208
http://ocs.med.nyu.edu/microscopy & http://microscopynotes.com/


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of csadangi
Sent: Thursday, September 11, 2014 3:06 PM
To: [hidden email]
Subject: Re: Batch channel splitter

Hi Curtis,

That was helpful. I think i can save them in .JPEG format by substituting .TIFF with .JPEG?
But it again gives me all the 3 channels and i need only 1. So how can i do that? Also, now it doesn't tell me which one is blue, green or red.

Any help would be highly appreciated



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009589.html
Sent from the ImageJ mailing list archive at Nabble.com.

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

Jeff Spector-2
In reply to this post by csadangi
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
Reply | Threaded
Open this post in threaded view
|

Re: Batch channel splitter

csadangi
so i have developed/modified three macros. One for both red & green, one only for red and one for green. Thank you everyone for your guidance and help :)

"for both"

dir1 = getDirectory("open file ");
list = getFileList(dir1);
dir2 = dir1+"splits"+File.separator;
File.makeDirectory(dir2);  
for (i=0; i<list.length; i++)
        {
       
        if (File.isDirectory(dir1+list[i])){}
        else{
               
                path = dir1+list[i];
                if (endsWith(path, ".db")){}
                else{
                       
                        open(path);
                        if (bitDepth!=24){}  
                        else {
                                setBatchMode(true);
                                title = File.nameWithoutExtension ;
                                run("Split Channels");
                                close();
                               
                                saveAs("Jpeg", dir2+title+"green.jpg");
                                close();
                                saveAs("Jpeg", dir2+title+"red.jpg");
                                close();
                                setBatchMode(false);

                                }
                        }
                }
        }

===========
"GREEN"

dir1 = getDirectory("open file ");
list = getFileList(dir1);
dir2 = dir1+"splits"+File.separator;
File.makeDirectory(dir2);
for (i=0; i<list.length; i++)
        {
       
        if (File.isDirectory(dir1+list[i])){}
        else{
               
                path = dir1+list[i];
                if (endsWith(path, ".db")){}
                else{
                       
                        open(path);
                        if (bitDepth!=24){}  
                        else {
                                setBatchMode(true);
                                title = File.nameWithoutExtension ;
                                run("Split Channels");
                                close();
                               
                               
                                saveAs("Jpeg", dir2+title+"green.jpg");
                                close();
                                close();
                                setBatchMode(false);

                                }
                        }
                }
        }
==========

"RED"

dir1 = getDirectory("open file ");
list = getFileList(dir1);
dir2 = dir1+"splits"+File.separator;
File.makeDirectory(dir2);  
for (i=0; i<list.length; i++)
        {
       
        if (File.isDirectory(dir1+list[i])){}
        else{
               
                path = dir1+list[i];
                if (endsWith(path, ".db")){}
                else{
                       
                        open(path);
                        if (bitDepth!=24){}  
                        else {
                                setBatchMode(true);
                                title = File.nameWithoutExtension ;
                                run("Split Channels");
                                close();
                               
                               
                                close();
                                saveAs("Jpeg", dir2+title+"red.jpg");
                                close();
                                setBatchMode(false);

                                }
                        }
                }
        }