Error in script "GetTitle"

Hi all,
I don’t have any experience with writing script so I used the built-in recorder.
However I need to add title=getTitle() to the script to make sure it also works for images with another name.
run(“Split Channels”);
title = getTitle();
selectWindow(" + title + (green) ")

When imageJ splits the channels, three new images are created. I want to select the one in the green channel. How do I correct the error in the third line?
It is like this in the recorder:
run(“Split Channels”);
selectWindow(“SOM - Chamber 1 + sterile water + 7dpi 26-10-2020-Image Export-01_c1-2.jpg (green)”);

selectWindow(title + " (green)");
1 Like

Hi Marlies,
I think you also need to put the "title = getTitle(); " line before the Split channels command to get the original image, rather than one produced after the split command. You can check by:
print(getTitle()); or
print(“title is:”, title);

3 Likes

Thank you!
I am having another issue with this script. Besides cell count, I now also would also like to have the measurements for area etc from the ‘’ green" channels immages so I added the following:

run(“Set Measurements…”, “area mean standard min median display redirect =[title + " (green)”] decimal=2");

How do I correct this?

Hi @Marlies

Create your title string and use it in ‘Set Measurements’ by sting concatenation.

titleRD =  title + " (green)";

run("Set Measurements...", "area mean standard min integrated redirect=" + titleRD + " decimal=3");

or alternatively you can use a different code style:
(with exactly the same function)

titleRD =  title + " (green)";

run("Set Measurements...", "area mean standard min integrated redirect=&titleRD decimal=3");

Hi Peter,
This is the entire script. It still gives an error in line 4… I think I need to learn programming in c!
I thought If title TitelRD is defined als title + " (green") then maybe I don’t need to add the + before and after TitleRD in line 5? However it still doesn’t work if I change line 5 to

run(“Set Measurements…”, “area mean standard min integrated redirect=“titleRD” decimal=3”);

title = getTitle();
run(“Split Channels”);
selectWindow(title + " (green)");
titleRD = title + " (green)";
run(“Set Measurements…”, “area mean standard min integrated redirect=” + titleRD + " decimal=3");
setAutoThreshold(“Default dark”);
//run(“Threshold…”);
setThreshold(40, 255);
//setThreshold(40, 255);
setOption(“BlackBackground”, true);
run(“Convert to Mask”);
run(“Analyze Particles…”, “size=100-Infinity pixel circularity=0.30-1.00 show=Overlay display clear summarize add”);

thank you again!

Hi @Marlies

in your code please make sure to
use " and not
use ... and not

(Use Preformatted text to post your code.)

Sorry, there was a mistake in the statements of my last post.

Maybe the following macro can help:

title = getTitle();
run("Split Channels");
titleRD = title + " (green)";
run("Set Measurements...", "area mean standard min integrated redirect=[" + titleRD + "] decimal=3");

//  *** Select a channel for cell detection
selectWindow(titleRD);
//selectWindow(title + " (red)");
//selectWindow(title + " (blue)");

//  *** Dublicate this channel (to make sure that your green channel will not be binarized by thresholding)
run("Duplicate...", "title=DUB");

//  *** Threshold and create Mask
setAutoThreshold("Default dark");
//setThreshold(40, 255);
setOption("BlackBackground", true);
run("Convert to Mask");

run("Analyze Particles...", "size=100-Infinity pixel circularity=0.30-1.00 show=Overlay display clear summarize add");