Posted by
Christine Labno-2 on
May 19, 2017; 7:58pm
URL: http://imagej.273.s1.nabble.com/Macro-to-measure-particles-and-save-ROI-on-to-original-image-tp5018747p5018767.html
Hi Eloise,
"I think if you write run("Duplicate...", "title=list[i]+_original"); it should work. No spaces, and you can use the list of the directory images as you loop through them."
Unfortunately this suggestion leads to an image named list[i]+_original and the macro breaks down just like in the original version. Likewise run("Duplicate...", "title=imgName + 'original '"); doesn't work. Adding text strings to variables after the Duplicate command is tricky, it doesn't work like adding text strings to variables in other commands (like selectWindow(imgName + "_original"); works, for example).
The absolute easiest way to rename an image duplicate with the name you want is to add
rename(imgName + "original");
on the line immediately after the Duplicate command, like this:
run("Duplicate...", "title="); <-- doesn't matter what title= because it will be replaced right away
rename(imgName + "original");
That will get you what you want and keep your code intact.
Also, if I may suggest, your strategy to strip off ".tiff" from your image name to get to the baseName variable also doesn't work as written.
Replace this: baseNameEnd=indexOf(imgName, ".tif");
with this: baseNameEnd=lastIndexOf(imgName, ".");
and you should be good to go.
Finally, because I know someone else will suggest this, you could work with image IDs instead of image names. Every image or copy of an image has a unique ID, even if they have the same names. Something like original=getImageID(); then duplicate, then copy=getImageID(); and then later selectImage(original); or selectImage(copy);
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 eloiselockyer [
[hidden email]]
Sent: Thursday, May 18, 2017 6:07 AM
To:
[hidden email]
Subject: Macro to measure particles and save ROI on to original image
I am trying to write an imageJ macro that will
1) Open and split an image into two channels
2) Perform particle analysis on each image and save measurements
3) Save the original image with the particle outlines overlayed
So far I have realised I need to first duplicate the original image so that
the ROI can later be saved on top of this. However I at the moment I can't
figure out how to rename this duplicated image so I can later select it for
flattening:
dir=getDirectory("Choose a Directory");
print(dir);
greenDir=dir + "/Green/";
blueDir=dir + "/Blue/";
print(greenDir);
print(blueDir);
File.makeDirectory(greenDir);
File.makeDirectory(blueDir);
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("C1-" + imgName);
run("Duplicate...", "title= imgName + "original");
selectWindow("C1-" + imgName);
setAutoThreshold("Default dark");
//run("Threshold...");
//setThreshold(1, 255);
run("Convert to Mask");
run("Analyze Particles...", "size=60-Infinity pixel show=Outlines
display exclude summarize add");
selectWindow(imgName + "original");
roiManager("Show All without labels");
run("Flatten");
saveAs("Tiff", greenDir + baseName + "green.tif");
close();
I know the error is in the run("Duplicate...", "title= imgName +
"original"); line, but I don't know what's wrong with the code!
--
View this message in context:
http://imagej.1557.x6.nabble.com/Macro-to-measure-particles-and-save-ROI-on-to-original-image-tp5018747.htmlSent 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