1

I have a small problem with imagej: I have .tif files in a folder, which consist of three different files (blue channel, green channel, red channel). I would like to convert them to separate pictures, then to only keep the green one I want to do this with a macro, but i can't get it to work. I can open the .tif, then convert it to separate images (Image-0001, Image-0002 and Image-0003). But then i want to rename them to blueImage, greenImage and redImage.

Googling got me to this, but this one saves the images as separate files and it gives an error.

macro split_color{ 
    dir1 = getDirectory("InputDir"); 
    list = getFileList(dir1); 
    dir2 = getDirectory("OutpurDir"); 
    for (i=0; i<list.length; i++) { 
        open(dir1+list[i]); 
        title1=File.nameWithoutExtension; 
        for (j=1; j<=3; j++){ 
            run("Stack to Images")
            "  slices="+j); 
            run("8-bit"); 
            if (j==1) c = "blue"; 
            else if(j==2) c = "green"; 
            else c = "red"; 
            saveAs("tif", dir2+title1+"-"+c+".tif"); 
            wait(100); 
            close(); 
        } 
        close(); 
    } 
    showMessage("Macro is finished"); 
} 

I can't get this to work, anyone who could help me?

Thanks

Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51
DCZ
  • 1,584
  • 1
  • 12
  • 18
  • 2
    In order to save time of those trying to help you, you should provide 1) the error message ("it gives an error" is rather unspecific) and 2) the link that you found ("Googling got me to this"). Also, have a look at the [macro language documentation](http://imagej.net/developer/macro/macros.html) – Jan Eglinger Feb 08 '16 at 11:30
  • 1
    There's a problem in line 10 of your macro code: `" slices="+j);` is not a valid command. – Jan Eglinger Feb 08 '16 at 11:39

0 Answers0