Hi all,
I'm struggling a bit with what I presume must be a fairly simple task. I have a load of images that have been acquired as stacks with the first slice being DAPI, and the second being 488. I want to find a way to split these into separate images and save them with file names that obviously relate to each other and to the original image. I can do this manually, but have hundreds of images that need this doing to them. There must be a way to batch it with a macro or plugin, but I'm not a programmer! Any help greatly appreciated. Kind regards, Ash |
Hi Ash- I just did this with a different goal, but the same basic problem and I am also not a programmer. Attached is a macro I came up with after lots of help from the list. Paste it into your startup macros set and then modify. If you remove my "run" scale and label etc. commands with your tasks, the shell should be the same. I would use the recorder to find the commands you need to split the stack (I am guessing stack to hyperstack and then split channels from the hyperstack and put those in place of my run commands near the end. It asks you for a folder where the original are and then asks for a folder to put the processed files into. Dave
macro "batch process folder scale and make movie2"{ requires("1.33s"); dir = getDirectory("Choose a Directory "); dir2 = getDirectory("Choose Destination Directory "); setBatchMode(true); count = 0; countFiles(dir); n = 0; processFiles(dir, dir2); //print(count+" files processed"); } function countFiles(dir) { list = getFileList(dir); for (i=0; i<list.length; i++) { if (endsWith(list[i], "/")) countFiles(""+dir+list[i]); else count++; } } function processFiles(dir, dir2) { list = getFileList(dir); for (i=0; i<list.length; i++) { if (endsWith(list[i], "/")) processFiles(""+dir+list[i], dir2); else { showProgress(n++, count); path = dir+list[i]; processFile(path, dir2); } } } function processFile(path,dir2) { if (endsWith(path, ".tif")) { open(path); title1=getTitle(); run("8-bit"); run("Properties...", " unit=pixel pixel_width=.64 pixel_height=.64 voxel_depth=1.0000 frame=[5 min] origin=0,0"); run("Scale...", "x=.7 y=.7 interpolation=Bilinear average process create"); run("Label...", "format=00:00 starting=0 interval=4 x=800 y=20 font=18 text=hr:min "); run("QuickTime Movie...", "compression=MPEG-4 quality=Normal frame=20 save=[/dir2/test.mov]"); run("Close All"); call("java.lang.System.gc"); } } On Mar 14, 2012, at 1:43 PM, Ash Dunne wrote: > Hi all, > > I'm struggling a bit with what I presume must be a fairly simple task. > > I have a load of images that have been acquired as stacks with the first > slice being DAPI, and the second being 488. > > I want to find a way to split these into separate images and save them with > file names that obviously relate to each other and to the original image. I > can do this manually, but have hundreds of images that need this doing to > them. There must be a way to batch it with a macro or plugin, but I'm not a > programmer! > > Any help greatly appreciated. > > Kind regards, > > Ash > > -- > View this message in context: http://imagej.1557.n6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p4578247.html > Sent from the ImageJ mailing list archive at Nabble.com. Visiting Professor David Knecht Beatson Institute for Cancer Research University of Glasgow Switchback Road, Bearsden Glasgow Scotland G61 1BD UK Visiting Professor David Knecht Beatson Institute for Cancer Research University of Glasgow Switchback Road, Bearsden Glasgow Scotland G61 1BD UK |
In reply to this post by Ash Dunne
Hi Ash,
it is not 100% clear what you want, but maybe a macro like the following? You could run it with Process>Batch>Macro It assumes your input images are tiffs, each of them a stack that contains two images, the first with the DAPI and the second with the 488. title=getTitle(); if (endsWith(title, ".tif")) title = substring(title, 0, lengthOf(title)-4); //remove '.tif' at the end dir=getDirectory("image"); //assumes you want to save into the original directory setSlice(1); titleD=title+"_DAPI.tif" run("Duplicate...", "title=["titleD+"]"); saveAs("Tiff", dir+titleD); close(); setSlice(2); title488=title+"_488.tif" run("Duplicate...", "title=["title488+"]"); saveAs("Tiff", dir+title488); close(); close(); //closes the original (I have note really tried the macro - I have no such images. So there may be bugs in it, and I leave it to you to debug it) Michael ________________________________________________________________ On Mar 14, 2012, at 14:43, Ash Dunne wrote: > Hi all, > > I'm struggling a bit with what I presume must be a fairly simple task. > > I have a load of images that have been acquired as stacks with the first > slice being DAPI, and the second being 488. > > I want to find a way to split these into separate images and save them with > file names that obviously relate to each other and to the original image. I > can do this manually, but have hundreds of images that need this doing to > them. There must be a way to batch it with a macro or plugin, but I'm not a > programmer! > > Any help greatly appreciated. > > Kind regards, > > Ash > > -- > View this message in context: http://imagej.1557.n6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p4578247.html > Sent from the ImageJ mailing list archive at Nabble.com. |
Hi Michael and Dave,
Thanks for your input. I appreciate the help! I've almost got there by modifying Michael's macros (haven't had a proper look at yours yet Dave). What I'm getting at the moment is that when I run the macro as batch, I am also getting duplicates of the original file in the destination folder. Not a massive problem, but it would be great if I could sort that out once and for all. I think it's because the Batch box is already asking for an output folder and file type. Is there anyway to stop it saving the duplicated original file? Here's what I'm currently using: title=getTitle(); if(endsWith(title, ".tif")) title=substring(title, 0, lengthOf(title)-4); dir="\\\\AIFNAS3\\AIFdatasets\\Dom James\\2012-03scan\\test batch split\\"; titleD=title+"_DAPI.tif"; setSlice(1); run("Duplicate...", "title=titleD"); saveAs("Tiff", dir+titleD); close(); setSlice(2); titleG=title+"_488.tif"; run("Duplicate...", "title=titleG"); saveAs("Tiff", dir+titleG); close(); close(); |
In reply to this post by Ash Dunne
Hi Ash,
did you set an output directory in Process>Batch>Macro? This might explain why the original is saved. As I understand it, the original file won't be saved if the'Output...' field in the dialog is empty. Michael ________________________________________________________________ Ash Dunne wrote: > Hi Michael and Dave, > > Thanks for your input. I appreciate the help! > > I've almost got there by modifying Michael's macros (haven't had a proper > look at yours yet Dave). > > What I'm getting at the moment is that when I run the macro as batch, I am > also getting duplicates of the original file in the destination folder. Not > a massive problem, but it would be great if I could sort that out once and > for all. > > I think it's because the Batch box is already asking for an output folder > and file type. Is there anyway to stop it saving the duplicated original > file? > > Here's what I'm currently using: > > title=getTitle(); > if(endsWith(title, ".tif")) > title=substring(title, 0, lengthOf(title)-4); > dir="\\\\AIFNAS3\\AIFdatasets\\Dom James\\2012-03scan\\test batch split\\"; > titleD=title+"_DAPI.tif"; > setSlice(1); > run("Duplicate...", "title=titleD"); > saveAs("Tiff", dir+titleD); > close(); > setSlice(2); > titleG=title+"_488.tif"; > run("Duplicate...", "title=titleG"); > saveAs("Tiff", dir+titleG); > close(); > close(); > > -- > View this message in context: > http://imagej.1557.n6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p4620695.html |
Hi Michael,
Perfect! This explained it. I was a bit of a dunce and assumed that you had to input a value in the Output field. This now works perfectly! Thanks so much for your help. Ash |
In reply to this post by Ash Dunne
Hello I am having a similar problem.
I have Images which I want to split into the three colour channels. I have worked out the commands that I would like to be performed on the green and blue images once they have been split, but when it comes to putting it into a batch command process I don't know how to change my code so that it will apply to all of the images in the directory I want to use and select the blue image to do the following steps with. This is what I would like to happen to the BLUE images: open("FOLDER NAMEf"); run("Split Channels"); selectWindow[THIS IS WHERE I THINK I NEED TO PUT THE FILE NAME OF THE SPLIT WINDOW???] //run("Brightness/Contrast..."); setMinAndMax(0, 50); run("Close"); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); run("Measure"); I would then like the Green and Blue images to be saved to separate directorys and discard the red image. I am not a programmer so any help would be greatly appreciated. Thanks, Christina |
Hello Christina,
This code should do what you want, holding the name of the file under the variable t and then using ImageJ's habit of naming split images "original name (blue)", etc. to select the image to process. Just set up the two folders for saving the blue and the green images before you run the macro so that you can select them when the macro asks for them. It will only ask for the folders once before batch processing all. May I suggest that between yoursetThreshold command and your Measure command you insert some code to tell the macro what you want to measure and whether or not you want the measurements limited to the thresholded area (record under Analyze --> Set Measurements). Kind Regards, Christine ---------------------begin code----------------- dir = getDirectory("Choose a Directory to PROCESS"); list = getFileList(dir); dir2 = getDirectory("Choose a Directory for SAVING the BLUE Image"); dir3 = getDirectory("Choose a Directory for SAVING the GREEN Image"); setBatchMode(true); for (f=0; f<list.length; f++) { path = dir+list[f]; print(path); showProgress(f, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) { if (endsWith(path,"f")) { t=getTitle(); s=lastIndexOf(t, '.'); ts=substring(t, 0,s); ts2= t +'blue image.tif'; ts3= t +'green image.tif'; //open("FOLDER NAMEf"); run("Split Channels"); selectWindow(t + " (blue)"); //run("Brightness/Contrast..."); setMinAndMax(0, 50); //run("Close"); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); run("Measure"); rename(ts2); saveAs("Tiff", dir2 + ts2 + ".tif"); run("Close"); selectWindow(t + " (green)"); rename(ts3); saveAs("Tiff", dir3 + ts3 + ".tif"); run("Close"); run("Close All"); } } } ---------------------end code---------------- -------------------------------------------- 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 cmparkes [[hidden email]] Sent: Wednesday, November 26, 2014 9:21 AM To: [hidden email] Subject: Re: Batch splitting of stacks and saving Hello I am having a similar problem. I have Images which I want to split into the three colour channels. I have worked out the commands that I would like to be performed on the green and blue images once they have been split, but when it comes to putting it into a batch command process I don't know how to change my code so that it will apply to all of the images in the directory I want to use and select the blue image to do the following steps with. This is what I would like to happen to the BLUE images: open("FOLDER NAMEf"); run("Split Channels"); selectWindow[THIS IS WHERE I THINK I NEED TO PUT THE FILE NAME OF THE SPLIT WINDOW???] //run("Brightness/Contrast..."); setMinAndMax(0, 50); run("Close"); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); run("Measure"); I would then like the Green and Blue images to be saved to separate directorys and discard the red image. I am not a programmer so any help would be greatly appreciated. Thanks, Christina -- View this message in context: http://imagej.1557.x6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p5010643.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 |
Thank you so much for your help Christine! The code you helped me with works beautifully. I added the suggested section about setting the threshold measurements but I need to try and save the 'measurements' which I take from the images as they are being created and saved into their subfolders. I have tried to add a section of code to change the name of the result in the result window to the name of the file it came from and to keep the results window open and save it as a text file at the end.
I've attached my updated code. I've highlighted in Red where I have made additions ----------------begining of code----------------------- dir = getDirectory("Choose a Directory to PROCESS"); list = getFileList(dir); dir2 = getDirectory("Choose a Directory for SAVING the Total Cell Image"); dir3 = getDirectory("Choose a Directory for SAVING the GFP Cell Image"); setBatchMode(true); for (f=0; f<list.length; f++) { path = dir+list[f]; print(path); showProgress(f, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) { if (endsWith(path,"f")) { t=getTitle(); s=lastIndexOf(t, '.'); ts=substring(t, 0,s); ts2= t +'total.tif'; ts3= t +'gfp.tif'; //open("FOLDER NAMEf"); { run("Split Channels"); selectWindow(t+"(blue)"); //run("Brightness/Contrast..."); setMinAndMax(0, 50); //run("Close"); //run("Enhance Contrast...", "saturated=2 normalize"); //run("Find Edges"); run("Set Measurements...", "area standard area_fraction limit redirect=None decimal=1"); name(getTitle() selectWindow(name) setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); //run("Measure"); data - newArray(""+getResult("area_standard")+"", ""+getResult("area_fraction")+""); } selectWindow(t + " (blue)"); rename(ts2); saveAs("Tiff", dir2 + ts2 + ".tif"); run("Close"); selectWindow(t + " (green)"); rename(ts3); saveAs("Tiff", dir3 + ts3 + ".tif"); run("Close"); selectWindow("Results"); dotIndex = "s"; if (dotIndex!=-1); path = substring(path, 0, dotIndex); // remove extension save(path+"-results.txt"); close() run("Close All"); } } } --------------------end of code----------------- However whenever I run the code I get this error message: No window with *first file title in the process folder*.tif(blue)" found. Which was not seen before. The additional bits of code were added to:- 1) Name the file from which the measurements were collected 2) Create a new results table with the area and area fraction results 3) Code telling the macro what to measure 4) Renaming the files and the destination files If you could look over my additions, that would be most helpful. Also do you have any literature that you suggest I read to get more of an understanding of how to write these kind of macros? Best Wishes Christina Parkes Department of Women's and Children's Health University of Liverpool Date: Wed, 26 Nov 2014 12:25:33 -0800 From: [hidden email] To: [hidden email] Subject: Re: Batch splitting of stacks and saving Hello Christina, This code should do what you want, holding the name of the file under the variable t and then using ImageJ's habit of naming split images "original name (blue)", etc. to select the image to process. Just set up the two folders for saving the blue and the green images before you run the macro so that you can select them when the macro asks for them. It will only ask for the folders once before batch processing all. May I suggest that between yoursetThreshold command and your Measure command you insert some code to tell the macro what you want to measure and whether or not you want the measurements limited to the thresholded area (record under Analyze --> Set Measurements). Kind Regards, Christine ---------------------begin code----------------- dir = getDirectory("Choose a Directory to PROCESS"); list = getFileList(dir); dir2 = getDirectory("Choose a Directory for SAVING the BLUE Image"); dir3 = getDirectory("Choose a Directory for SAVING the GREEN Image"); setBatchMode(true); for (f=0; f<list.length; f++) { path = dir+list[f]; print(path); showProgress(f, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) { if (endsWith(path,"f")) { t=getTitle(); s=lastIndexOf(t, '.'); ts=substring(t, 0,s); ts2= t +'blue image.tif'; ts3= t +'green image.tif'; //open("FOLDER NAMEf"); run("Split Channels"); selectWindow(t + " (blue)"); //run("Brightness/Contrast..."); setMinAndMax(0, 50); //run("Close"); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); run("Measure"); rename(ts2); saveAs("Tiff", dir2 + ts2 + ".tif"); run("Close"); selectWindow(t + " (green)"); rename(ts3); saveAs("Tiff", dir3 + ts3 + ".tif"); run("Close"); run("Close All"); } } } ---------------------end code---------------- -------------------------------------------- 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 cmparkes [[hidden email]] Sent: Wednesday, November 26, 2014 9:21 AM To: [hidden email] Subject: Re: Batch splitting of stacks and saving Hello I am having a similar problem. I have Images which I want to split into the three colour channels. I have worked out the commands that I would like to be performed on the green and blue images once they have been split, but when it comes to putting it into a batch command process I don't know how to change my code so that it will apply to all of the images in the directory I want to use and select the blue image to do the following steps with. This is what I would like to happen to the BLUE images: open("FOLDER NAMEf"); run("Split Channels"); selectWindow[THIS IS WHERE I THINK I NEED TO PUT THE FILE NAME OF THE SPLIT WINDOW???] //run("Brightness/Contrast..."); setMinAndMax(0, 50); run("Close"); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); run("Measure"); I would then like the Green and Blue images to be saved to separate directorys and discard the red image. I am not a programmer so any help would be greatly appreciated. Thanks, Christina -- View this message in context: http://imagej.1557.x6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p5010643.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 If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p5010645.html
|
Hi Christina,
This email is going to be long and may not interest everyone, but I'm sending it back to you via the ImageJ listhost so that the archives may help other beginning macro writers. First up, for something you (or anyone) can read about macro writing, there are a few tutorials out there, maybe others can chime in with more. . . http://www.sussex.ac.uk/gdsc/intranet/pdfs/ImageJBatchProcessing.pdf - by Alex Herbert, from the ImageJ Tutorials and Examples section http://digital.bsd.uchicago.edu/ImagejandFijiHelp.html#tutorials - documentation that goes with my ImageJ classes at the University of Chicago, including the Macro Writing workshop Power Point http://cmci.embl.de/documents/ijcourses#macro_programming_in_imagej - CMCI ImageJ Course books, put together, I believe, by Kota Miura at EMBL More specifically for you: The red coloring did not come through in your message, but I think I found most of your changes. I can tell you why you get the "no window found" error message. . . because there is no window with the title you are feeding to ImageJ. Somewhere along the line a critical space was left out of the file name and this: selectWindow(t + " (blue)"); became this: selectWindow(t + "(blue)"); They are not equivalent from ImageJ's standpoint. With the additional space between the " and the ( , the code works again. As far as I can tell none of the other instances of "selectWindow" were effected, but be careful about that in the future. ImageJ, like all computer programs, is maddeningly literal. I've been known to break code by putting a "G" when I really need "g" and tiny things like that. To address your points: 1) there is a mechanism to name the file from which the measurements are collected. That is the point of the ts2 and ts3 variables, which you have changed to reflect your tastes in image naming, so bravo. Unfortunately when I wrote the code the name is only put on at the saving step, and I have a feeling that you want it before the measurement step so that the name shows up in the data table. This is reasonable :) All that needs to be done is to move up the renaming step to BEFORE the measurement step (i.e. move the rename(ts2); command to replace name(getTitle()selectWindow(name)setAutoThreshold("Default dark"); which as far as I can tell is not doing anything). I also added the "display" command to the setMeasurements line, which will cause ImageJ to put the name of the file (as set by rename) into the Results table. 2) the run("Measure"); command would normally create the data table you want, but it won't when there are // in front of it. // "comment out" code and cause it not to be run by the macro. Therefore in your current code it is NOT running the majority of your processing steps, including Find edges, threshold and measure. In other words, you have told the macro NOT to do exactly what you WANT it to do. 3) You did correctly add code telling the macro what to measure, which is this: run("Set Measurements...", "area standard area_fraction limit redirect=None decimal=1"); so awesome there. Again, the run("Measure"); command will take care of doing the actual measurements, but only if you remove the // (!!!) and in the final version of the code I added the display command to write in the name of each file along with it's measurements. I'm not 100% sure what this line of code was hoping to achieve: data - newArray(""+getResult("area_standard")+"", ""+getResult("area_fraction")+""); but it may have been that you thought this would create the data table. I think this code will GET a result from the data table so that it could be placed in an array and used elsewhere, which is handy, but not as far as I can tell what you want to do. I think you can do without this line of code. 4) I think this renaming was addressed in point 1, although I did add some code to save the full data table at the end. Right now the table is set to save to the same folder as the Total Cell images, but that can be changed, as well as the name "total results.xls" Right now it is set to save one large data table at the end, with the names of all the files measured in the table so you know which result came from which image (this is why it is outside the }}} close loop brackets, it's only done once after all measurements are done). I think this makes more sense than having as many data tables as you have images and then having to collate them all at the end, but I could be wrong. Finally, here is what I would use as your final code, but feel free to modify as you wish ------------------begin------------------- dir = getDirectory("Choose a Directory to PROCESS"); list = getFileList(dir); dir2 = getDirectory("Choose a Directory for SAVING the Total Cell Image"); dir3 = getDirectory("Choose a Directory for SAVING the GFP Cell Image"); setBatchMode(true); for (f=0; f<list.length; f++) { path = dir+list[f]; print(path); showProgress(f, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) { if (endsWith(path,"f")) { t=getTitle(); s=lastIndexOf(t, '.'); ts=substring(t, 0,s); ts2= ts +' total.tif'; ts3= ts +' gfp.tif'; run("Split Channels"); selectWindow(t + " (blue)"); //run("Brightness/Contrast..."); setMinAndMax(0, 50); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); rename(ts2); run("Set Measurements...", "area standard area_fraction limit display redirect=None decimal=1"); run("Threshold..."); setThreshold(0, 193); run("Measure"); selectWindow(ts2); saveAs("Tiff", dir2 + ts2); close(); selectWindow(t + " (green)"); rename(ts3); saveAs("Tiff", dir3 + ts3); close(); selectWindow(t + " (red)"); close(); } } } selectWindow("Results"); saveAs("Results", dir2 + " total results.xls"); ------------------------end----------------------- Hope this is helpful. 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 cmparkes [[hidden email]] Sent: Monday, December 01, 2014 11:01 AM To: [hidden email] Subject: Re: Batch splitting of stacks and saving Thank you so much for your help Christine! The code you helped me with works beautifully. I added the suggested section about setting the threshold measurements but I need to try and save the 'measurements' which I take from the images as they are being created and saved into their subfolders. I have tried to add a section of code to change the name of the result in the result window to the name of the file it came from and to keep the results window open and save it as a text file at the end. I've attached my updated code. I've highlighted in Red where I have made additions ----------------begining of code----------------------- dir = getDirectory("Choose a Directory to PROCESS"); list = getFileList(dir); dir2 = getDirectory("Choose a Directory for SAVING the Total Cell Image"); dir3 = getDirectory("Choose a Directory for SAVING the GFP Cell Image"); setBatchMode(true); for (f=0; f<list.length; f++) { path = dir+list[f]; print(path); showProgress(f, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) { if (endsWith(path,"f")) { t=getTitle(); s=lastIndexOf(t, '.'); ts=substring(t, 0,s); ts2= t +'total.tif'; ts3= t +'gfp.tif'; //open("FOLDER NAMEf"); {run("Split Channels"); selectWindow(t+"(blue)"); //run("Brightness/Contrast..."); setMinAndMax(0, 50); //run("Close"); //run("Enhance Contrast...", "saturated=2 normalize"); //run("Find Edges"); run("Set Measurements...", "area standard area_fraction limit redirect=None decimal=1");name(getTitle()selectWindow(name)setAutoThreshold("Default dark");//run("Threshold..."); setThreshold(0, 193); //run("Measure"); data - newArray(""+getResult("area_standard")+"", ""+getResult("area_fraction")+"");}selectWindow(t + " (blue)"); rename(ts2); saveAs("Tiff", dir2 + ts2 + ".tif"); run("Close"); selectWindow(t + " (green)"); rename(ts3); saveAs("Tiff", dir3 + ts3 + ".tif"); run("Close"); selectWindow("Results"); dotIndex = "s"; if (dotIndex!=-1); path = substring(path, 0, dotIndex); // remove extension save(path+"-results.txt"); close() run("Close All"); } } } --------------------end of code----------------- However whenever I run the code I get this error message: No window with *first file title in the process folder*.tif(blue)" found. Which was not seen before. The additional bits of code were added to:- 1) Name the file from which the measurements were collected 2) Create a new results table with the area and area fraction results 3) Code telling the macro what to measure 4) Renaming the files and the destination files If you could look over my additions, that would be most helpful. Also do you have any literature that you suggest I read to get more of an understanding of how to write these kind of macros? Best Wishes Christina Parkes Miss Christina ParkesDepartment of Women's and Children's HealthUniversity of Liverpool Date: Wed, 26 Nov 2014 12:25:33 -0800 From: [hidden email] To: [hidden email] Subject: Re: Batch splitting of stacks and saving Hello Christina, This code should do what you want, holding the name of the file under the variable t and then using ImageJ's habit of naming split images "original name (blue)", etc. to select the image to process. Just set up the two folders for saving the blue and the green images before you run the macro so that you can select them when the macro asks for them. It will only ask for the folders once before batch processing all. May I suggest that between yoursetThreshold command and your Measure command you insert some code to tell the macro what you want to measure and whether or not you want the measurements limited to the thresholded area (record under Analyze --> Set Measurements). Kind Regards, Christine ---------------------begin code----------------- dir = getDirectory("Choose a Directory to PROCESS"); list = getFileList(dir); dir2 = getDirectory("Choose a Directory for SAVING the BLUE Image"); dir3 = getDirectory("Choose a Directory for SAVING the GREEN Image"); setBatchMode(true); for (f=0; f<list.length; f++) { path = dir+list[f]; print(path); showProgress(f, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) { if (endsWith(path,"f")) { t=getTitle(); s=lastIndexOf(t, '.'); ts=substring(t, 0,s); ts2= t +'blue image.tif'; ts3= t +'green image.tif'; //open("FOLDER NAMEf"); run("Split Channels"); selectWindow(t + " (blue)"); //run("Brightness/Contrast..."); setMinAndMax(0, 50); //run("Close"); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); run("Measure"); rename(ts2); saveAs("Tiff", dir2 + ts2 + ".tif"); run("Close"); selectWindow(t + " (green)"); rename(ts3); saveAs("Tiff", dir3 + ts3 + ".tif"); run("Close"); run("Close All"); } } } ---------------------end code---------------- -------------------------------------------- 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 cmparkes [[hidden email]] Sent: Wednesday, November 26, 2014 9:21 AM To: [hidden email] Subject: Re: Batch splitting of stacks and saving Hello I am having a similar problem. I have Images which I want to split into the three colour channels. I have worked out the commands that I would like to be performed on the green and blue images once they have been split, but when it comes to putting it into a batch command process I don't know how to change my code so that it will apply to all of the images in the directory I want to use and select the blue image to do the following steps with. This is what I would like to happen to the BLUE images: open("FOLDER NAMEf"); run("Split Channels"); selectWindow[THIS IS WHERE I THINK I NEED TO PUT THE FILE NAME OF THE SPLIT WINDOW???] //run("Brightness/Contrast..."); setMinAndMax(0, 50); run("Close"); run("Enhance Contrast...", "saturated=2 normalize"); run("Find Edges"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(0, 193); run("Measure"); I would then like the Green and Blue images to be saved to separate directorys and discard the red image. I am not a programmer so any help would be greatly appreciated. Thanks, Christina -- View this message in context: http://imagej.1557.x6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p5010643.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 If you reply to this email, your message will be added to the discussion below: http://imagej.1557.x6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p5010645.html To unsubscribe from Batch splitting of stacks and saving, click here. NAML -- View this message in context: http://imagej.1557.x6.nabble.com/Batch-splitting-of-stacks-and-saving-tp4578247p5010710.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 |
Free forum by Nabble | Edit this page |