0

我正在尝试编写一个 imageJ 宏,它将

1) 打开图像并将其拆分为两个通道 2) 对每个图像进行粒子分析并保存测量值 3) 保存原始图像并覆盖粒子轮廓

到目前为止,我已经意识到我需要先复制原始图像,以便以后可以将 ROI 保存在此之上。但是我现在不知道如何重命名这个重复的图像,所以我可以稍后选择它进行展平:

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(); 

如果这是非常简单的事情,请提前抱歉,这对我来说都是全新的,并且从谷歌搜索中学到了!

4

2 回答 2

1

我昨晚修改了我的代码,现在它正在工作:

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"); 
     roiManager("Reset"); 

         selectWindow("C1-" + imgName);  
     run("Duplicate...", "title=");
     saveAs("Tiff", greenDir + "originalgreen" + baseName); 
     selectWindow("C1-" + imgName); 
     setAutoThreshold("Default dark");
     //run("Threshold...");
     //setThreshold(1, 255);
     setOption("BlackBackground", false);
     run("Convert to Mask");
     run("Analyze Particles...", "size=60-Infinity pixel show=Outlines display exclude   summarize   add");
     selectWindow("originalgreen" + imgName); 
     roiManager("Show All with labels");
     run("Flatten");
     saveAs("Tiff", greenDir + baseName + "overlaygreen.tif"); 
         close(); 
     } 
} 

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");
     roiManager("Reset"); 


         selectWindow("C2-" + imgName); 
     run("Duplicate...", "title=");
     saveAs("Tiff", blueDir + "originalblue" + baseName);
     selectWindow("C2-" + imgName);
     //run("Threshold...");
     //setThreshold(23, 255);
     setOption("BlackBackground", false);
     run("Convert to Mask");
     run("Analyze Particles...", "size=60-Infinity pixel show=Outlines display exclude   summarize   add");
     selectWindow("originalblue" + imgName); 
     roiManager("Show All with labels");
     run("Flatten");
         saveAs("Tiff", blueDir + baseName + "overlayblue.tif"); 
         run("Close All"); 
     } 
} 
于 2017-05-19T14:57:23.237 回答
0

ImageJ 中的每个 GUI 操作都可以使用宏记录器以不同的脚本语言记录,这是一个很大的帮助,请参阅:

https://imagej.nih.gov/ij/docs/guide/146-31.html#sub:记录...

http://imagej.net/Introduction_into_Macro_Programming

重命名的宏命令很简单:rename("YourImageTitle");

于 2017-05-18T13:13:28.380 回答