Merge Channels Macro

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

Merge Channels Macro

Lucasphi
Hi,

I'm trying to write a macro where an RGB image is split into three channels and then RB are merged together and GB are merged together.  I'm a little confused on how the arguments for run("Merge Channels...", "") works.  I'm not sure what to put for red= and blue= and how to get the action to also "keep original sources" but not "create composite".  Could anyone help me out?

So far, my code looks something like this




for (i=0; i<filename.length; i++) {
        if(endsWith(filename[i], ".tif")) {
                open(path+filename[i]);

                run("Split Channels");

                run("Merge Channel…", "red=["+red+"] green=*none* blue["+blue+"] gray=*none false true);
                rename(filename[i]+"_488");
                run("8bit");
                saveAs("tiff", newDir+getTitle);
                close();
Reply | Threaded
Open this post in threaded view
|

Re: Merge Channels Macro

Michael Schmid
Hi Lucas,

you simply need to find out how the output images of "Split Channels"  
are named:
   red = filename[i]+" (red)";
   blue = filename[i]+" (blue)";

Also note that checkboxes are not activated/deactivated with true/
false, but with giving the first word of the checkbox name to  
activate it or omitting to deactivate.
So you have, e.g.,
   .... gray=*None* keep ignore

for "Keep source images" and "Ignore source LUTs" on, but "Create  
Composite" off.
If you want to create two output images, you will probably want to  
have "Keep source images" on when creating the first one and off when  
creating the second one.


Michael
________________________________________________________________


On 9 Jun 2011, at 09:57, Lucasphi wrote:

> Hi,
>
> I'm trying to write a macro where an RGB image is split into three  
> channels
> and then RB are merged together and GB are merged together.  I'm a  
> little
> confused on how the arguments for run("Merge Channels...", "")  
> works.  I'm
> not sure what to put for red= and blue= and how to get the action  
> to also
> "keep original sources" but not "create composite".  Could anyone  
> help me
> out?
>
> So far, my code looks something like this
>
>
>
>
> for (i=0; i<filename.length; i++) {
>         if(endsWith(filename[i], ".tif")) {
>                 open(path+filename[i]);
>
> run("Split Channels");
>
> run("Merge Channel…", "red=["+red+"] green=*none* blue["+blue+"]
> gray=*none false true);
> rename(filename[i]+"_488");
> run("8bit");
> saveAs("tiff", newDir+getTitle);
> close();
Reply | Threaded
Open this post in threaded view
|

Re: Merge Channels Macro

Krs5
In reply to this post by Lucasphi
Hi Lucas,



You could try after opening your image:



title = getTitle;

run("Split Channels");

selectWindow(title+" (red)");

titleRed = getTitle;

selectWindow(title+" (green)");

titleGreen = getTitle;

run("Merge Channels...", "red=titleRed green=titleGreen blue=*None* gray=*None* keep");

Good luck



Kees



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Lucasphi
Sent: 09 June 2011 08:57
To: [hidden email]
Subject: Merge Channels Macro



Hi,



I'm trying to write a macro where an RGB image is split into three channels

and then RB are merged together and GB are merged together.  I'm a little

confused on how the arguments for run("Merge Channels...", "") works.  I'm

not sure what to put for red= and blue= and how to get the action to also

"keep original sources" but not "create composite".  Could anyone help me

out?



So far, my code looks something like this









for (i=0; i<filename.length; i++) {

        if(endsWith(filename[i], ".tif")) {

                open(path+filename[i]);



            run("Split Channels");



            run("Merge Channel…", "red=["+red+"] green=*none* blue["+blue+"]

gray=*none false true);

            rename(filename[i]+"_488");

            run("8bit");

            saveAs("tiff", newDir+getTitle);

            close();



--

View this message in context: http://imagej.588099.n2.nabble.com/Merge-Channels-Macro-tp6456923p6456923.html

Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Merge Channels Macro

Lucasphi
In reply to this post by Michael Schmid
Thanks for all of your input everyone! You guys are wonderful <3 Here is the final code if you guys wanted to see it.  What it does is it batch processes and splits multichannel images into separate RGB channels,  pairs RB and GB, sets it to 8bit and inverts it. Cheers!


path = getDirectory("Choose a Directory");
filename = getFileList(path);

newDir = path + "Single_Channel" + File.separator;
File.makeDirectory(newDir);  


for (i=0; i<filename.length; i++) {
        if(endsWith(filename[i], ".tif")) {
                open(path+filename[i]);
                red = filename[i]+" (red)";
                blue = filename[i]+" (blue)";
                green = filename[i]+" (green)";


                run("Split Channels");

                run("Merge Channels...", "red=["+red+"] green=*None* blue=["+blue+"] gray=*None* keep ignore");
                rename(filename[i]+"_external");
                run("8-bit");
                run("Invert");
                saveAs("tiff", newDir+getTitle);
               

                run("Merge Channels...", "red=*None* green=["+green+"] blue=["+blue+"] gray=*None* keep ignore");
                rename(filename[i]+"_internal");
                run("8-bit");
                run("Invert");
                saveAs("tiff", newDir+getTitle);
                close();close();close();close();close();
                setBatchMode(false);
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Merge Channels Macro

mmettlen
I'm trying to write a macro in which the user chooses which open images to merge. Thus, my macro includes: run("Merge Channels..."};. Now, I'd like to activate by default "keep" and "create". However, if I include in my macro run("Merge Channels...", "keep, create");, the merging runs through without giving the user the possibility to choose what channels to merge. Any way around that?
Reply | Threaded
Open this post in threaded view
|

Re: Merge Channels Macro

Cammer, Michael
First set up a dialog that prompts the user for the information.  http://rsbweb.nih.gov/ij/developer/macro/functions.html#D
Then use the answers the user inputs to do the merge.

===========================================================================
Michael Cammer, Microscopy Core & Dustin Lab , Skirball Institute, NYU Langone Medical Center
Cell:  914-309-3270   Lab: 212-263-3208
http://ocs.med.nyu.edu/microscopy & http://www.med.nyu.edu/skirball-lab/dustinlab/

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of mmettlen
Sent: Thursday, February 20, 2014 9:39 AM
To: [hidden email]
Subject: Re: Merge Channels Macro

I'm trying to write a macro in which the user chooses which open images to merge. Thus, my macro includes: /run("Merge Channels..."};/. Now, I'd like to activate by default "keep" and "create". However, if I include in my macro /run("Merge Channels...", "keep, create");/, the merging runs through without giving the user the possibility to choose what channels to merge.
Any way around that?




--
View this message in context: http://imagej.1557.x6.nabble.com/Merge-Channels-Macro-tp3684311p5006600.html
Sent from the ImageJ mailing list archive at Nabble.com.

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

------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

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

Re: Merge Channels Macro

Christine Labno-2
Hello,

Michael is right, you need to set up a dialog to ask the user for information.  Here is some example code that I created a long time ago -- it's not elegant, but it does the job you want -- you can use this as a guide to create your own dialog.  

------------snip---------------
//begin with three separate images, one for red, one for green and one for blue.
//open the images and then run the macro

run("Images to Stack", "name=Stack title=[] use");
t1=getInfo("slice.label");
setSlice(2);
t2=getInfo("slice.label");
setSlice(3);
t3=getInfo("slice.label");

Dialog.create("Color Choices");
Dialog.addChoice("Red:", newArray(t1, t2, t3));
Dialog.addChoice("Green:", newArray(t1, t2, t3));
Dialog.addChoice("Blue:", newArray(t1, t2, t3));

Dialog.show();
R = Dialog.getChoice();
G = Dialog.getChoice();;
B = Dialog.getChoice();;;


run("Stack to Images");

selectWindow(R);
rename("red");
selectWindow(G);
rename("green");
selectWindow(B);
rename("blue");


run("Merge Channels...", "c1=[red] c2=[green] c3=[blue]");

--------------snip----------------------------------------

Best,
Christine

--------------------------------------------
Christine Labno, Ph.D.
Asst. Technical Director
Light Microscopy Core
University of Chicago
Office of Shared Research Facilities
KCBD 1250 900 E. 57th St.
(773) 834-9040 (phone)

________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of Cammer, Michael [[hidden email]]
Sent: Thursday, February 20, 2014 10:28 AM
To: [hidden email]
Subject: Re: Merge Channels Macro

First set up a dialog that prompts the user for the information.  http://rsbweb.nih.gov/ij/developer/macro/functions.html#D
Then use the answers the user inputs to do the merge.

===========================================================================
Michael Cammer, Microscopy Core & Dustin Lab , Skirball Institute, NYU Langone Medical Center
Cell:  914-309-3270   Lab: 212-263-3208
http://ocs.med.nyu.edu/microscopy & http://www.med.nyu.edu/skirball-lab/dustinlab/

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of mmettlen
Sent: Thursday, February 20, 2014 9:39 AM
To: [hidden email]
Subject: Re: Merge Channels Macro

I'm trying to write a macro in which the user chooses which open images to merge. Thus, my macro includes: /run("Merge Channels..."};/. Now, I'd like to activate by default "keep" and "create". However, if I include in my macro /run("Merge Channels...", "keep, create");/, the merging runs through without giving the user the possibility to choose what channels to merge.
Any way around that?




--
View this message in context: http://imagej.1557.x6.nabble.com/Merge-Channels-Macro-tp3684311p5006600.html
Sent from the ImageJ mailing list archive at Nabble.com.

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

------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

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

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