Trouble with macro for split & merge 4 channels. Help!

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

Trouble with macro for split & merge 4 channels. Help!

Joana A.
Hi,

Disclaimer: I'm completely new to imageJ and macro writing.
 
I have many confocal images (4 channels, format .lif) that need to be analysed and I was advised to use image J, namely macros.
So I've spent the last 2 days reading posts here in the forum, trying lots of macros and even using the recorder but none really does exactly what I need:
1. split channels
2. change color
3. adjust B&C for each channel
4. run 6 different merges
5. Add scale 50um
6. save each merge as tiff format in a new directory.

However, today I have managed to successfully split and adjust B&C of one selected image with this macro:

path = getDirectory("Choose a Directory");
filename = getFileList(path);
newDir = path + "Single_Channel" + File.separator;
File.makeDirectory(newDir);  
title = getTitle();

run("Split Channels");
getTitle();
selectWindow("C4-" + title);
run("Green");
//run("Brightness/Contrast...");
setMinAndMax(25, 100);
run("Apply LUT");
selectWindow("C3-" + title);
run("Grays");
//run("Brightness/Contrast...");
setMinAndMax(60, 150)
run("Apply LUT");
selectWindow("C2-" + title);
run("Red");
//run("Brightness/Contrast...");
setMinAndMax(25, 150)
run("Apply LUT");
selectWindow("C1-" + title);
//run("Brightness/Contrast...");
setMinAndMax(10, 200)
run("Apply LUT");

And this is great but when trying to start merging the problems start. I guess I don't have the correct variables and lack a lot of understanding/knowledge of this language.
Thus, the following macro does not find the images although it does on the previous macro(split):

title = getTitle();
four = "C4-" + title;
three = "C3-" + title;
two = "C2-" + title;
one = "C1-" + title;

selectWindow("C4-" + title);
run("Merge Channels...", "c1=[two] c3=[one] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_actin");

run("Merge Channels...", "c1=[two] c3=[one] c4=[three] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vinc+actin");

run("Merge Channels...", "c2=[four] c3=[one] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vecad");

run("Merge Channels...", "c2=[four] c3=[one] c4=[three] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vecad+vinc");

run("Merge Channels...", "c3=[one] c4=[three] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vinc");

run("Merge Channels...", "c1=[two] c2=[four] c3=[one] c4=[three] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_merge");



Conclusion: I tried and tried but cant do it myself and I need help. Is there a way this can work sequentially in one macro: split and merge? Can anyone help me?

Thank you!
Joana
PhD student
Cardiovascular Sciences
Amsterdam, NL
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with macro for split & merge 4 channels. Help!

Olivier Burri
Hello.

Instead of
run("Merge Channels...", "c3=[one] c4=[three] keep"); saveAs("Tiff", newDir+getTitle+"_vinc");

remember that to include avariable in text you nedd to do
"text"+variable+"text"

So the above becomes
run("Merge Channels...", "c3=["+one+"] c4=["+three+"] keep"); saveAs("Tiff", newDir+getTitle+"_vinc");



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Joana A.
Sent: dimanche, 22 mai 2016 19:16
To: [hidden email]
Subject: Trouble with macro for split & merge 4 channels. Help!

Hi,

Disclaimer: I'm completely new to imageJ and macro writing.
 
I have many confocal images (4 channels, format .lif) that need to be analysed and I was advised to use image J, namely macros.
So I've spent the last 2 days reading posts here in the forum, trying lots of macros and even using the recorder but none really does exactly what I
need:
1. split channels
2. change color
3. adjust B&C for each channel
4. run 6 different merges
5. Add scale 50um
6. save each merge as tiff format in a new directory.

However, today I have managed to successfully split and adjust B&C of one selected image with this macro:

path = getDirectory("Choose a Directory"); filename = getFileList(path); newDir = path + "Single_Channel" + File.separator;
File.makeDirectory(newDir);  
title = getTitle();

run("Split Channels");
getTitle();
selectWindow("C4-" + title);
run("Green");
//run("Brightness/Contrast...");
setMinAndMax(25, 100);
run("Apply LUT");
selectWindow("C3-" + title);
run("Grays");
//run("Brightness/Contrast...");
setMinAndMax(60, 150)
run("Apply LUT");
selectWindow("C2-" + title);
run("Red");
//run("Brightness/Contrast...");
setMinAndMax(25, 150)
run("Apply LUT");
selectWindow("C1-" + title);
//run("Brightness/Contrast...");
setMinAndMax(10, 200)
run("Apply LUT");

And this is great but when trying to start merging the problems start. I guess I don't have the correct variables and lack a lot of understanding/knowledge of this language.
Thus, the following macro does not find the images although it does on the previous macro(split):

title = getTitle();
four = "C4-" + title;
three = "C3-" + title;
two = "C2-" + title;
one = "C1-" + title;

selectWindow("C4-" + title);
run("Merge Channels...", "c1=[two] c3=[one] keep"); run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide"); saveAs("Tiff", newDir+getTitle+"_actin");

run("Merge Channels...", "c1=[two] c3=[one] c4=[three] keep"); run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide"); saveAs("Tiff", newDir+getTitle+"_vinc+actin");

run("Merge Channels...", "c2=[four] c3=[one] keep"); run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide"); saveAs("Tiff", newDir+getTitle+"_vecad");

run("Merge Channels...", "c2=[four] c3=[one] c4=[three] keep"); run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide"); saveAs("Tiff", newDir+getTitle+"_vecad+vinc");

run("Merge Channels...", "c3=[one] c4=[three] keep"); run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide"); saveAs("Tiff", newDir+getTitle+"_vinc");

run("Merge Channels...", "c1=[two] c2=[four] c3=[one] c4=[three] keep"); run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide"); saveAs("Tiff", newDir+getTitle+"_merge");



Conclusion: I tried and tried but cant do it myself and I need help. Is there a way this can work sequentially in one macro: split and merge? Can anyone help me?

Thank you!
Joana



-----
PhD student
Cardiovascular Sciences
Amsterdam, NL
--
View this message in context: http://imagej.1557.x6.nabble.com/Trouble-with-macro-for-split-merge-4-channels-Help-tp5016490.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: Trouble with macro for split & merge 4 channels. Help!

George Patterson
Hi Joana,
In addition to changes for including variables in the Merge Channels
commands, you may need to remove the title=getTitle() located just before
you define your string variables.
If you use this command after you've split the channels, I think the title
will have C1, C2, C3, or C4 as a prefix and with your code it's search for
images entitled something like this "C4-C1-title".
George

On Mon, May 23, 2016 at 3:45 AM, Burri Olivier <[hidden email]>
wrote:

> Hello.
>
> Instead of
> run("Merge Channels...", "c3=[one] c4=[three] keep"); saveAs("Tiff",
> newDir+getTitle+"_vinc");
>
> remember that to include avariable in text you nedd to do
> "text"+variable+"text"
>
> So the above becomes
> run("Merge Channels...", "c3=["+one+"] c4=["+three+"] keep");
> saveAs("Tiff", newDir+getTitle+"_vinc");
>
>
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> Joana A.
> Sent: dimanche, 22 mai 2016 19:16
> To: [hidden email]
> Subject: Trouble with macro for split & merge 4 channels. Help!
>
> Hi,
>
> Disclaimer: I'm completely new to imageJ and macro writing.
>
> I have many confocal images (4 channels, format .lif) that need to be
> analysed and I was advised to use image J, namely macros.
> So I've spent the last 2 days reading posts here in the forum, trying lots
> of macros and even using the recorder but none really does exactly what I
> need:
> 1. split channels
> 2. change color
> 3. adjust B&C for each channel
> 4. run 6 different merges
> 5. Add scale 50um
> 6. save each merge as tiff format in a new directory.
>
> However, today I have managed to successfully split and adjust B&C of one
> selected image with this macro:
>
> path = getDirectory("Choose a Directory"); filename = getFileList(path);
> newDir = path + "Single_Channel" + File.separator;
> File.makeDirectory(newDir);
> title = getTitle();
>
> run("Split Channels");
> getTitle();
> selectWindow("C4-" + title);
> run("Green");
> //run("Brightness/Contrast...");
> setMinAndMax(25, 100);
> run("Apply LUT");
> selectWindow("C3-" + title);
> run("Grays");
> //run("Brightness/Contrast...");
> setMinAndMax(60, 150)
> run("Apply LUT");
> selectWindow("C2-" + title);
> run("Red");
> //run("Brightness/Contrast...");
> setMinAndMax(25, 150)
> run("Apply LUT");
> selectWindow("C1-" + title);
> //run("Brightness/Contrast...");
> setMinAndMax(10, 200)
> run("Apply LUT");
>
> And this is great but when trying to start merging the problems start. I
> guess I don't have the correct variables and lack a lot of
> understanding/knowledge of this language.
> Thus, the following macro does not find the images although it does on the
> previous macro(split):
>
> title = getTitle();
> four = "C4-" + title;
> three = "C3-" + title;
> two = "C2-" + title;
> one = "C1-" + title;
>
> selectWindow("C4-" + title);
> run("Merge Channels...", "c1=[two] c3=[one] keep"); run("Scale Bar...",
> "width=50 height=8 font=28 color=White background=None location=[Lower
> Right] hide"); saveAs("Tiff", newDir+getTitle+"_actin");
>
> run("Merge Channels...", "c1=[two] c3=[one] c4=[three] keep"); run("Scale
> Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide"); saveAs("Tiff",
> newDir+getTitle+"_vinc+actin");
>
> run("Merge Channels...", "c2=[four] c3=[one] keep"); run("Scale Bar...",
> "width=50 height=8 font=28 color=White background=None location=[Lower
> Right] hide"); saveAs("Tiff", newDir+getTitle+"_vecad");
>
> run("Merge Channels...", "c2=[four] c3=[one] c4=[three] keep"); run("Scale
> Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide"); saveAs("Tiff",
> newDir+getTitle+"_vecad+vinc");
>
> run("Merge Channels...", "c3=[one] c4=[three] keep"); run("Scale Bar...",
> "width=50 height=8 font=28 color=White background=None location=[Lower
> Right] hide"); saveAs("Tiff", newDir+getTitle+"_vinc");
>
> run("Merge Channels...", "c1=[two] c2=[four] c3=[one] c4=[three] keep");
> run("Scale Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide"); saveAs("Tiff", newDir+getTitle+"_merge");
>
>
>
> Conclusion: I tried and tried but cant do it myself and I need help. Is
> there a way this can work sequentially in one macro: split and merge? Can
> anyone help me?
>
> Thank you!
> Joana
>
>
>
> -----
> PhD student
> Cardiovascular Sciences
> Amsterdam, NL
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Trouble-with-macro-for-split-merge-4-channels-Help-tp5016490.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
>

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

Re: Trouble with macro for split & merge 4 channels. Help!

Joana A.
Dear George,

Thank you so much for your input.
I have corrected the macro as you suggested: replace this "c3=[one] for this "c3=["+one+"].

Then also removed the title=getTitle(); variable. Because indeed, as you well mentioned, I was getting the error "cannot find C4-C4-filename". However now, the following variables
four = "C4-" +title;
three = "C3-" +title;
two = "C2-"+title;
one = "C1-"+title;
dont make sense anymore and the program cannot find images named C4-title.
So, I need your help again I'm afraid.
I've tried to remove the "+title" but get the same type of error, obviously... C4- means nothing.

Thus the question now is - how should my variables be defined now that "title" has no meaning? How do I write "select image that starts with C4- (for example) and consider that a variable named "four"?
four= ???
three= ???
two= ???
one= ???

Once again, thank you so much for help me out! Much appreciated.
Joana
PhD student
Cardiovascular Sciences
Amsterdam, NL
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with macro for split & merge 4 channels. Help!

George Patterson
Hi Joana,
Perhaps I misunderstood your macro code.  Was all of the code part of one
macro?  Or are you running the first part (split channels, applyLUT etc.)
in one macro and then the second part (merge channels) in a second macro?
If so, the string variable "title" would not be defined in the second
macro.  Is there some reason you cannot combine the code into one macro.

If you need to use two macros, I suggest placing something like this right
before you define your string variables in the second macro.

a=getTitle();
title=substring(a,3);//this should return the title without the prefix

best,
George



On Mon, May 23, 2016 at 11:37 AM, Joana A. <[hidden email]> wrote:

> Dear George,
>
> Thank you so much for your input.
> I have corrected the macro as you suggested: replace this "c3=[one] for
> this
> "c3=["+one+"].
>
> Then also removed the title=getTitle(); variable. Because indeed, as you
> well mentioned, I was getting the error "cannot find C4-C4-filename".
> However now, the following variables
> four = "C4-" +title;
> three = "C3-" +title;
> two = "C2-"+title;
> one = "C1-"+title;
> dont make sense anymore and the program cannot find images named C4-title.
> So, I need your help again I'm afraid.
> I've tried to remove the "+title" but get the same type of error,
> obviously... C4- means nothing.
>
> Thus the question now is - how should my variables be defined now that
> "title" has no meaning? How do I write "select image that starts with C4-
> (for example) and consider that a variable named "four"?
> four= ???
> three= ???
> two= ???
> one= ???
>
> Once again, thank you so much for help me out! Much appreciated.
> Joana
>
>
>
>
> -----
> PhD student
> Cardiovascular Sciences
> Amsterdam, NL
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Trouble-with-macro-for-split-merge-4-channels-Help-tp5016490p5016497.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: Trouble with macro for split & merge 4 channels. Help!

Joana A.
Hi George,

Yes, my idea was to have 1 single macro for both split & merge processes. But I'm failing on the latter.
Splitting works like a charm but then it gets stuck when the merge starts.
This is what I have at the moment. Cant you take a look?

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

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

title = getTitle();
four = "C4-" + title;
three = "C3-" + title;
two = "C2-" + title;
one = "C1-" + title;

run("Split Channels");
selectWindow("C4-" + title);
run("Green");
//run("Brightness/Contrast...");
setMinAndMax(25, 100);
run("Apply LUT");
selectWindow("C3-" + title);
run("Grays");
//run("Brightness/Contrast...");
setMinAndMax(60, 150)
run("Apply LUT");
selectWindow("C2-" + title);
run("Red");
//run("Brightness/Contrast...");
setMinAndMax(25, 150)
run("Apply LUT");
selectWindow("C1-" + title);
//run("Brightness/Contrast...");
setMinAndMax(10, 200)
run("Apply LUT");
run("Tile") //4 channels are split and B&C adjusted
 
run("Merge Channels...", "c1=["+two"] c3=["+one"] keep"); //error message !!!
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_actin");

run("Merge Channels...", "c1=["+two"] c3=["+one"] c4=["+three"] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vinc+actin");

run("Merge Channels...", "c2=["+four"] c3=["+one"] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vecad");

run("Merge Channels...", "c2=["+four"] c3=["+one"] c4=["+three"] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vecad+vinc");

run("Merge Channels...", "c3=["+one"] c4=["+three"] keep");
run("Scale Bar...", "width=50 height=8 font=28 color=White background=None location=[Lower Right] hide");
saveAs("Tiff", newDir+getTitle+"_vinc");

the error message i get is:
')' expected in line 36
run (Merge Channels..." , "c1=[" + two <"] c3=[" > + one"] keep");

I'm sorry I dont understand it but what does this error mean? spaces needed?
This is getting me a bit frustrated... I feel like i'm so close to getting the merge done but still can't do it.
Arghhh!


Joana

PhD student
Cardiovascular Sciences
Amsterdam, NL
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with macro for split & merge 4 channels. Help!

George Patterson
Hi Joana,
For lines such as the following:

run("Merge Channels...", "c1=["+two"] c3=["+one"] keep");

change to:

run("Merge Channels...", "c1=["+two+"] c3=["+one+"] keep");

As written in your macro now, it's reached the end of the arguments after
your variable and expects the ");" which normally ends the command.
best,
George

On Mon, May 23, 2016 at 1:06 PM, Joana A. <[hidden email]> wrote:

> Hi George,
>
> Yes, my idea was to have 1 single macro for both split & merge processes.
> But I'm failing on the latter.
> Splitting works like a charm but then it gets stuck when the merge starts.
> This is what I have at the moment. Cant you take a look?
>
> path = getDirectory("Choose a Directory");
> filename = getFileList(path);
>
> newDir = path + "Single_Channel" + File.separator;
> File.makeDirectory(newDir);
>
> title = getTitle();
> four = "C4-" + title;
> three = "C3-" + title;
> two = "C2-" + title;
> one = "C1-" + title;
>
> run("Split Channels");
> selectWindow("C4-" + title);
> run("Green");
> //run("Brightness/Contrast...");
> setMinAndMax(25, 100);
> run("Apply LUT");
> selectWindow("C3-" + title);
> run("Grays");
> //run("Brightness/Contrast...");
> setMinAndMax(60, 150)
> run("Apply LUT");
> selectWindow("C2-" + title);
> run("Red");
> //run("Brightness/Contrast...");
> setMinAndMax(25, 150)
> run("Apply LUT");
> selectWindow("C1-" + title);
> //run("Brightness/Contrast...");
> setMinAndMax(10, 200)
> run("Apply LUT");
> run("Tile") //4 channels are split and B&C adjusted
>
> run("Merge Channels...", "c1=["+two"] c3=["+one"] keep"); //error message
> !!!
> run("Scale Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide");
> saveAs("Tiff", newDir+getTitle+"_actin");
>
> run("Merge Channels...", "c1=["+two"] c3=["+one"] c4=["+three"] keep");
> run("Scale Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide");
> saveAs("Tiff", newDir+getTitle+"_vinc+actin");
>
> run("Merge Channels...", "c2=["+four"] c3=["+one"] keep");
> run("Scale Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide");
> saveAs("Tiff", newDir+getTitle+"_vecad");
>
> run("Merge Channels...", "c2=["+four"] c3=["+one"] c4=["+three"] keep");
> run("Scale Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide");
> saveAs("Tiff", newDir+getTitle+"_vecad+vinc");
>
> run("Merge Channels...", "c3=["+one"] c4=["+three"] keep");
> run("Scale Bar...", "width=50 height=8 font=28 color=White background=None
> location=[Lower Right] hide");
> saveAs("Tiff", newDir+getTitle+"_vinc");
>
> the error message i get is:
> ')' expected in line 36
> run (Merge Channels..." , "c1=[" + two <"] c3=[" > + one"] keep");
>
> I'm sorry I dont understand it but what does this error mean? spaces
> needed?
> This is getting me a bit frustrated... I feel like i'm so close to getting
> the merge done but still can't do it.
> Arghhh!
>
>
> Joana
>
>
>
>
>
> -----
> PhD student
> Cardiovascular Sciences
> Amsterdam, NL
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Trouble-with-macro-for-split-merge-4-channels-Help-tp5016490p5016500.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: Trouble with macro for split & merge 4 channels. Help!

Joana A.
Dear George,

First of all, super thanks for the patience and availability to help such an imageJ newbie.
I though I already had corrected the syntax but looks like I've messed up my notepad files. My fault.

Second, the small changes made it work! I'm so happy! It works perfectly and in milliseconds!

Thank you so much.

Best regards,
Joana
PhD student
Cardiovascular Sciences
Amsterdam, NL
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with macro for split & merge 4 channels. Help!

Joana A.
In reply to this post by Olivier Burri
Dear Oliver,

Thank you so much for your input. It helped a lot!

Best,
Joana
PhD student
Cardiovascular Sciences
Amsterdam, NL