Hi there,
I'm a bit of a newbie in trying to write macro's for ImageJ, and have run into some trouble with what should be a relatively straightforward task. I would very much appreciate some feedback on writing a macro that splits channels in a 3-channel TIF and saves the 3 new TIFs, and does that with all the images in the same folder. So something like: 1. Open the ().czi image from a folder 2. Split channels 3. Save each of the 3 new files as a TIF 4. Open next file from the same folder and then 2-4 until all files from this folder are opened, converted and saved 5. Close all the windows I tried to record such macro... but did not go very far. The macro I came up with looks something like: T = getTitle(); selectWindow(T); run("Split Channels"); selectWindow("C1-"+T); Blue = getTitle(); selectWindow("C2-"+T); Green = getTitle(); selectWindow("C3-"+T); Red = getTitle(); run("Close All") While this does run, it only converts the stack to a .tiff file. As I said, I'm quite new to this so am not quite sure what I'm getting wrong. I would be really grateful to someone who could help me with this macro. Thanks for your time! Best, Oliver p.s. If I could incorporate a function to make a maximum intensity projection of each channel that would be awesome, as this will be my next challenge! |
Good day Oliver,
did you have a look at the many example macros that come with ImageJ or that are available from <https://imagej.nih.gov/ij/macros/>? "BatchProcessFolders" could be of interest for looping through files in a folder... HTH Herbie :::::::::::::::::::::::::::::::::::::::: Am 18.09.16 um 12:45 schrieb Harschnitz: > Hi there, > > I'm a bit of a newbie in trying to write macro's for ImageJ, and have run > into some trouble with what should be a relatively straightforward task. I > would very much appreciate some feedback on writing a macro that splits > channels in a 3-channel TIF and saves the 3 new TIFs, and does that with all > the images in the same folder. So something like: > > 1. Open the ().czi image from a folder > 2. Split channels > 3. Save each of the 3 new files as a TIF > 4. Open next file from the same folder and then 2-4 until all files from > this folder are opened, converted and saved > 5. Close all the windows > > I tried to record such macro... but did not go very far. The macro I came up > with looks something like: > > T = getTitle(); > selectWindow(T); > run("Split Channels"); > > selectWindow("C1-"+T); > Blue = getTitle(); > selectWindow("C2-"+T); > Green = getTitle(); > selectWindow("C3-"+T); > Red = getTitle(); > > run("Close All") > > While this does run, it only converts the stack to a .tiff file. As I said, > I'm quite new to this so am not quite sure what I'm getting wrong. > I would be really grateful to someone who could help me with this macro. > Thanks for your time! > > Best, Oliver > > p.s. If I could incorporate a function to make a maximum intensity > projection of each channel that would be awesome, as this will be my next > challenge! > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Macro-for-splitting-channels-troubleshooting-tp5017203.html > Sent 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 |
In reply to this post by Harschnitz
Hi Oliver,
Have you seen this page? http://imagej.net/Batch Regards, Curtis On Sep 18, 2016 6:01 AM, "Harschnitz" <[hidden email]> wrote: > Hi there, > > I'm a bit of a newbie in trying to write macro's for ImageJ, and have run > into some trouble with what should be a relatively straightforward task. I > would very much appreciate some feedback on writing a macro that splits > channels in a 3-channel TIF and saves the 3 new TIFs, and does that with > all > the images in the same folder. So something like: > > 1. Open the ().czi image from a folder > 2. Split channels > 3. Save each of the 3 new files as a TIF > 4. Open next file from the same folder and then 2-4 until all files from > this folder are opened, converted and saved > 5. Close all the windows > > I tried to record such macro... but did not go very far. The macro I came > up > with looks something like: > > T = getTitle(); > selectWindow(T); > run("Split Channels"); > > selectWindow("C1-"+T); > Blue = getTitle(); > selectWindow("C2-"+T); > Green = getTitle(); > selectWindow("C3-"+T); > Red = getTitle(); > > run("Close All") > > While this does run, it only converts the stack to a .tiff file. As I said, > I'm quite new to this so am not quite sure what I'm getting wrong. > I would be really grateful to someone who could help me with this macro. > Thanks for your time! > > Best, Oliver > > p.s. If I could incorporate a function to make a maximum intensity > projection of each channel that would be awesome, as this will be my next > challenge! > > > > -- > View this message in context: http://imagej.1557.x6.nabble. > com/Macro-for-splitting-channels-troubleshooting-tp5017203.html > Sent 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 |
Oliver, once your images are converted to tiff, use the following:
//SplitChannelMacro inputFolder= getDirectory("Choose a Directory"); print(inputFolder); outputRed= inputFolder + "/RedChannel/"; outputGreen= inputFolder + "/GreenChannel/“; outputBlue= inputFolder + “/BlueChannel/"; images= getFileList(inputFolder); File.makeDirectory(outputRed); File.makeDirectory(outputGreen); File.makeDirectory(outputBlue); for (i=0; i<images.length; i++) { setBatchMode(true); //batch mode inputPath= inputFolder + images[i]; open (inputPath); imagesName=getTitle(); print("Splitting Image: " + imagesName); run("Split Channels"); selectWindow(imagesName + " (blue)”); saveAs("Tiff", outputBlue + “blue_" +imagesName); close(); selectWindow(imagesName + " (green)"); saveAs("Tiff", outputGreen + "green_" +imagesName); close(); selectWindow(imagesName + " (red)"); saveAs("Tiff", outputRed + "red_"+imagesName); close(); write("Conversion Complete"); } setBatchMode(false); This is one I wrote to split all channels and save them in a new folder for each color. If it doesn’t work check how imageJ is naming your files after splitting. if they are different than in this macro (when I wrote this Fiji was appending "(color)” to my image names upon splitting), you may have to change the selectWindow commands to “C1- C2- C3-“ etc if they are not labeled “red green blue”. To put them all in one folder, just remove two of the output folders ("outputColor”) and the File.makeDirectory commands and name your new folder whatever you want. Make sure to change these in the saveAs commands as well. -Nick > On Sep 18, 2016, at 8:59 AM, Curtis Rueden <[hidden email]> wrote: > > Hi Oliver, > > Have you seen this page? > http://imagej.net/Batch > > Regards, > Curtis > > On Sep 18, 2016 6:01 AM, "Harschnitz" <[hidden email]> wrote: > >> Hi there, >> >> I'm a bit of a newbie in trying to write macro's for ImageJ, and have run >> into some trouble with what should be a relatively straightforward task. I >> would very much appreciate some feedback on writing a macro that splits >> channels in a 3-channel TIF and saves the 3 new TIFs, and does that with >> all >> the images in the same folder. So something like: >> >> 1. Open the ().czi image from a folder >> 2. Split channels >> 3. Save each of the 3 new files as a TIF >> 4. Open next file from the same folder and then 2-4 until all files from >> this folder are opened, converted and saved >> 5. Close all the windows >> >> I tried to record such macro... but did not go very far. The macro I came >> up >> with looks something like: >> >> T = getTitle(); >> selectWindow(T); >> run("Split Channels"); >> >> selectWindow("C1-"+T); >> Blue = getTitle(); >> selectWindow("C2-"+T); >> Green = getTitle(); >> selectWindow("C3-"+T); >> Red = getTitle(); >> >> run("Close All") >> >> While this does run, it only converts the stack to a .tiff file. As I said, >> I'm quite new to this so am not quite sure what I'm getting wrong. >> I would be really grateful to someone who could help me with this macro. >> Thanks for your time! >> >> Best, Oliver >> >> p.s. If I could incorporate a function to make a maximum intensity >> projection of each channel that would be awesome, as this will be my next >> challenge! >> >> >> >> -- >> View this message in context: http://imagej.1557.x6.nabble. >> com/Macro-for-splitting-channels-troubleshooting-tp5017203.html >> Sent 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Nick, thanks for your help. This looks like what I need! I will give it a go and see if I can get it to work.
|
Free forum by Nabble | Edit this page |