2017-04-20 34 views
0

我想將兩組熒光顯微鏡圖像合併爲綠色&藍色圖像,但我遇到了問題宏(以前沒有用過ImageJ)。我有一個FITC-images的文件夾被塗成綠色,一個DAPI-images的文件夾被塗成藍色。我一直在使用一個宏觀的這個修改後的版本我在網上找到:批量合併圖像錯誤(x.tif不是「C2(綠色):」的有效選擇)

macro "batch_merge_channel"{ 
    count = 1; 
    setBatchMode(true); 
    file1= getDirectory("Choose a Directory"); 
    list1= getFileList(file1); 
    n1=lengthOf(list1); 
    file2= getDirectory("Choose a Directory"); 
    list2= getFileList(file2); 
    n2=lengthOf(list2); 
    open(file1+list1[1]); 
    open(file2+list2[1]); 
    small = n1; 
    if(small<n2) 
     small = n2; 
     for(i=0;i<small;i++) 
    { 
      run("Merge Channels...", "c2="+list1[1]+ " c3="+list2[1]+ " keep"); 
      name = substring(list1, 0, 13)+")_merge"; 
      saveAs("tiff", "C:\\Merge\\"+name); 
      first += 2; 
      close(); 
      setBatchMode(false); 
     } 

然而這會返回一個錯誤

x.tif是不是一個有效的選擇「C2(綠色):」

其中x是第一個文件夾中第一個文件的名稱。

如果我手動合併圖像,兩個兩個,沒有錯誤。所以我假設問題出現在宏代碼中。 我在網上發現了這個錯誤的幾個案例,但沒有一個似乎適用於這些人爲我工作的解決方案。

任何幫助,將不勝感激!

回答

0

如果您還沒有解決這個問題,那麼在ImageJ問題上尋求幫助的好地方是forum

我可以建議一對夫婦的想法:

  • 是您的形象成功地由宏開的呢?您可以將批處理模式設置爲false來檢查這一點。
  • 它在我看來像for循環不採用變量i。它適用於第一對 圖像(list1[1], list2[1]),然後關閉合並的圖像,但 嘗試再次處理圖像1。要實際遍歷文件夾中的所有 圖像,您必須將放在的環內 像這樣(您不需要「保留」 - 最好不要將其保留,以便源圖像將自動關閉) open(file1+list1[i]); open(file2+list2[i]); run("Merge Channels...", "c2="+list1[i]+ " c3="+list2[i]); - 關閉批處理模式應該在循環之後完成,而不是在循環之內。

這是一個適合我的版本。

// @File(label = "Green images", style = "directory") file1 
 
// @File(label = "Blue images", style = "directory") file2 
 
// @File(label = "Output directory", style = "directory") output 
 

 
// Do not delete or move the top 3 lines! They contain essential parameters 
 

 
setBatchMode(true); 
 
list1= getFileList(file1); 
 
n1=lengthOf(list1); 
 
print("n1 = ",n1); 
 
list2= getFileList(file2); 
 
n2=lengthOf(list2); 
 
small = n1; 
 
if(small<n2) 
 
\t small = n2; 
 
for(i=0;i<small;i++) 
 
    { 
 
\t image1=list1[i]; 
 
\t image2=list2[i]; 
 
    open(file1+File.separator+list1[i]); 
 
    open(file2+File.separator+list2[i]); 
 
\t print("processing image",i); 
 
\t run("Merge Channels...", "c2=&image1 c3=&image2"); 
 
    name = substring(image1, 0, 13)+"_merge"; 
 
\t saveAs("tiff", output+File.separator+name); 
 
\t close(); 
 
\t } 
 
setBatchMode(false);

希望這有助於。

相關問題