Hello everyone,
I am looking for help to write a simple macro to open different single images in the same folder, combine them into a stack, and save the stack under a different name in a different folder. The images I want to combine have similar titles. For example: "w000_t000_tt000" , "w000_t000_tt001" , "w000_t000_tt002"... and "w001_t000_tt000" , "w001_t000_tt0001" , "w001_t000_tt002" ... Can this be done? Many thanks. Kind Regards, Jessica -- Jessica Davis MSc. Conway Institute of Biomolecular and Biomedical Research, University College Dublin, Belfield, Dublin 4. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hey. Well, I have the opposite macros for unstacking and saving images
under different names. So maybe you can use it as an example n=nSlices(); n=20; run("Stack to Images"); dir = getDirectory("Choose a source directory "); for (i=1; i<=n; i++) { a=i+100; showProgress(i, n); //setSlice(i); saveAs("Tiff", dir+a+".tif"); close(); g=dir+a; } Your macros should be something like (havent checked it, just I think so) n=20; dir = getDirectory("Choose a source directory "); for (i=1; i<=n; i++) { open("w000_t000_tt00"+a+".tif"); } run("Images to stack"); 2016-01-26 16:40 GMT+03:00 Jessica Davis <[hidden email]>: > Hello everyone, > > I am looking for help to write a simple macro to open different single > images in the same folder, combine them into a stack, and save the stack > under a different name in a different folder. > > The images I want to combine have similar titles. For example: > "w000_t000_tt000" , "w000_t000_tt001" , "w000_t000_tt002"... and > "w001_t000_tt000" , "w001_t000_tt0001" , "w001_t000_tt002" ... > > Can this be done? > > Many thanks. > > Kind Regards, > > Jessica > > -- > > Jessica Davis MSc. > > Conway Institute of Biomolecular and Biomedical Research, > University College Dublin, > Belfield, Dublin 4. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- Vasily A Popkov Lab.Structure and function of mitochondria A.N.Belozersky Institute of Physico-Chemical Biology Moscow State University -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Jessica Davis
Hi Jessica,
> I am looking for help to write a simple macro to open different single > images in the same folder, combine them into a stack, and save the > stack under a different name in a different folder. Try this: * Press L for Command Finder * Check the "Close window after running command" option * Type "Record." and press enter to run the Plugins>Macros>Record... function * Press L again * Type "Bio-Formats", down arrow, enter to run the File > Import > Bio-Formats command * Choose one of your files and press OK. * Check the "Group files with similar names" option of the Bio-Formats Importer Options dialog box. * All your files should open as a single stack * Use the File > Save As menu to save the stack to the desired output format * Now look at your Recorder window. It contains your macro to repeat the process. (You can prune out the "Command Finder" lines; they are unnecessary for the macro to work.) Regards, Curtis On Tue, Jan 26, 2016 at 7:40 AM, Jessica Davis <[hidden email]> wrote: > Hello everyone, > > I am looking for help to write a simple macro to open different single > images in the same folder, combine them into a stack, and save the stack > under a different name in a different folder. > > The images I want to combine have similar titles. For example: > "w000_t000_tt000" , "w000_t000_tt001" , "w000_t000_tt002"... and > "w001_t000_tt000" , "w001_t000_tt0001" , "w001_t000_tt002" ... > > Can this be done? > > Many thanks. > > Kind Regards, > > Jessica > > -- > > Jessica Davis MSc. > > Conway Institute of Biomolecular and Biomedical Research, > University College Dublin, > Belfield, Dublin 4. > > -- > 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 Jessica Davis
On 26/01/2016 3:40 PM, Jessica Davis wrote:
> Hello everyone, > > I am looking for help to write a simple macro to open different single > images in the same folder, combine them into a stack, and save the stack > under a different name in a different folder. > > The images I want to combine have similar titles. For example: > "w000_t000_tt000" , "w000_t000_tt001" , "w000_t000_tt002"... and > "w001_t000_tt000" , "w001_t000_tt0001" , "w001_t000_tt002" ... > > Can this be done? > > deigned to take a directory with x###_y###_z### and create x###_y### stacks which contain all of the z### images. I have a more developed python version, which does all sorts of other things. If you want that, or need clarification for this, feel free to ask: // beginning of macro------------------------------------------------------ inputPath = File.openDialog("choose an image file"); if (inputPath == "") { exit("User canceled the dialog"); } inputName = File.getName(inputPath); inputDir = File.getParent(inputPath); dirName = substring(inputDir, lastIndexOf(inputDir,"/")+1); print("input path: ", inputPath); print("input directory path: ", inputDir); print("input durectory name: ", dirName); // print(inputName); inputPrefix = substring(inputName, 0, lastIndexOf(inputName, ".")); // nprint(inputPrefix); fileList = getFileList(inputDir); // print(indexOf(fileList[fileList.length-1],"_x")+2); /* determine the number of fields in the x and y directions * The naming convention is: name_x###_y###_z### * total number of fields (numFields) = total number of files/number of z planes. * number of x fields is found by parsing x### in the last file of the input directory * number of y fields is (total fields)/(x fields) * */ // determine number of z-planes each xy field zPlanesStr = substring(fileList[fileList.length-1], indexOf(fileList[fileList.length-1],"_z")+2, indexOf(fileList[fileList.length-1],"_z")+5); zPlanes = parseInt(zPlanesStr); print("number of z planes: ",zPlanes); numFields = fileList.length/zPlanes; print("total number of fields: ",numFields); // Find total number of x### values xFieldsStr = substring(fileList[fileList.length-1], indexOf(fileList[fileList.length-1],"_x")+2, indexOf(fileList[fileList.length-1],"_x")+5); xFields = parseInt(xFieldsStr); // number in y direction must equal total/x-dimension. This can be verified to make it more robust. yFields = numFields/xFields; print("number of x fields: ",xFields, " number of y fields: ",yFields); sliceIndex = 1; // loop through all of the XY locations for (yLoc = 1; yLoc <= yFields; yLoc++) { for (xLoc = 1; xLoc <= xFields; xLoc++) { // open an image sequence fro all images which have the current XY location. This will be our z-stack run("Image Sequence...", "open="+inputDir+" file=x"+IJ.pad(d2s(xLoc,0),3)+"_y"+IJ.pad(d2s(yLoc,0),3)+" sort"); selectWindow(dirName); rename(dirName+"_"+IJ.pad(xLoc,3)+"_"+IJ.pad(yLoc,3)); } } // end of macro------------------------------------------------------ hope this helps --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by ctrueden
Hi Curtis,
Thank you for your response. When I follow your instructions, and I check the "Group files with similar names" option and press OK, I receive the following error: java.io.FileNotFoundException: E:\File and Library Storage\Desktop\USERS\Jessica Davis\Marina\pIL+Psfl-test4_20160126_120201\pIL+Psfl-test4_t0000_w0000_tt0000.tif (The system cannot find the file specified) at java.io.RandomAccessFile.open(Native Method) at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212) at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:123) at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:139) at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:148) at loci.common.Location.getHandle(Location.java:324) at loci.common.Location.getHandle(Location.java:294) at loci.common.Location.getHandle(Location.java:284) at loci.common.Location.getHandle(Location.java:274) at loci.common.Location.checkValidId(Location.java:349) at loci.formats.ImageReader.getReader(ImageReader.java:173) at loci.formats.ImageReader.setId(ImageReader.java:832) at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:651) at loci.formats.DimensionSwapper.setId(DimensionSwapper.java:293) at loci.formats.FileStitcher$ExternalSeries.<init>(FileStitcher.java:1264) at loci.formats.FileStitcher.initFile(FileStitcher.java:921) at loci.formats.FileStitcher.setId(FileStitcher.java:872) at loci.plugins.in.ImportProcess.initializeStack(ImportProcess.java:520) at loci.plugins.in.ImportProcess.execute(ImportProcess.java:147) at loci.plugins.in.Importer.showDialogs(Importer.java:140) at loci.plugins.in.Importer.run(Importer.java:76) at loci.plugins.LociImporter.run(LociImporter.java:78) at ij.IJ.runUserPlugIn(IJ.java:212) at ij.IJ.runPlugIn(IJ.java:176) at ij.Executer.runCommand(Executer.java:136) at ij.Executer.run(Executer.java:65) at java.lang.Thread.run(Thread.java:662) I am not familiar with computer programming language, so I am unsure what this error means. Each one of my files have similar names but would I need to change them to a more simple name for this to work? Kind Regards, Jessica On 26 January 2016 at 15:24, Curtis Rueden <[hidden email]> wrote: > Hi Jessica, > > > I am looking for help to write a simple macro to open different single > > images in the same folder, combine them into a stack, and save the > > stack under a different name in a different folder. > > Try this: > > * Press L for Command Finder > * Check the "Close window after running command" option > * Type "Record." and press enter to run the Plugins>Macros>Record... > function > * Press L again > * Type "Bio-Formats", down arrow, enter to run the File > Import > > Bio-Formats command > * Choose one of your files and press OK. > * Check the "Group files with similar names" option of the Bio-Formats > Importer Options dialog box. > * All your files should open as a single stack > * Use the File > Save As menu to save the stack to the desired output > format > * Now look at your Recorder window. It contains your macro to repeat the > process. (You can prune out the "Command Finder" lines; they are > unnecessary for the macro to work.) > > Regards, > Curtis > > On Tue, Jan 26, 2016 at 7:40 AM, Jessica Davis < > [hidden email]> > wrote: > > > Hello everyone, > > > > I am looking for help to write a simple macro to open different single > > images in the same folder, combine them into a stack, and save the stack > > under a different name in a different folder. > > > > The images I want to combine have similar titles. For example: > > "w000_t000_tt000" , "w000_t000_tt001" , "w000_t000_tt002"... and > > "w001_t000_tt000" , "w001_t000_tt0001" , "w001_t000_tt002" ... > > > > Can this be done? > > > > Many thanks. > > > > Kind Regards, > > > > Jessica > > > > -- > > > > Jessica Davis MSc. > > > > Conway Institute of Biomolecular and Biomedical Research, > > University College Dublin, > > Belfield, Dublin 4. > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- Jessica Davis MSc. Conway Institute of Biomolecular and Biomedical Research, University College Dublin, Belfield, Dublin 4. Tel: +353857444220 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Jessica,
Apologies for the long delay in reply. > When I follow your instructions, and I check the "Group files with > similar names" option and press OK, I receive the following error: > > java.io.FileNotFoundException: E:\File and Library > Storage\Desktop\USERS\Jessica > Davis\Marina\pIL+Psfl-test4_20160126_120201\pIL+Psfl-test4_t0000_w0000_tt0000.tif > (The system cannot find the file specified) That error suggests that perhaps there are one or more missing files in your collection? However, regardless of that, I would classify this error as a bug in Bio-Formats—it should at least emit something a little more clear about what the problem is. If you wish, you can report Bio-Formats bugs as described here: http://www.openmicroscopy.org/site/support/bio-formats/about/bug-reporting.html Regards, Curtis -- Curtis Rueden LOCI software architect - http://loci.wisc.edu/software ImageJ2 lead, Fiji maintainer - http://imagej.net/User:Rueden Did you know ImageJ has a forum? http://forum.imagej.net/ On Wed, Jan 27, 2016 at 5:51 AM, Jessica Davis <[hidden email]> wrote: > Hi Curtis, > > Thank you for your response. When I follow your instructions, and I check > the "Group files with similar names" option and press OK, I receive the > following error: > > java.io.FileNotFoundException: E:\File and Library > Storage\Desktop\USERS\Jessica > > Davis\Marina\pIL+Psfl-test4_20160126_120201\pIL+Psfl-test4_t0000_w0000_tt0000.tif > (The system cannot find the file specified) > at java.io.RandomAccessFile.open(Native Method) > at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212) > at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:123) > at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:139) > at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:148) > at loci.common.Location.getHandle(Location.java:324) > at loci.common.Location.getHandle(Location.java:294) > at loci.common.Location.getHandle(Location.java:284) > at loci.common.Location.getHandle(Location.java:274) > at loci.common.Location.checkValidId(Location.java:349) > at loci.formats.ImageReader.getReader(ImageReader.java:173) > at loci.formats.ImageReader.setId(ImageReader.java:832) > at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:651) > at loci.formats.DimensionSwapper.setId(DimensionSwapper.java:293) > at loci.formats.FileStitcher$ExternalSeries.<init>(FileStitcher.java:1264) > at loci.formats.FileStitcher.initFile(FileStitcher.java:921) > at loci.formats.FileStitcher.setId(FileStitcher.java:872) > at loci.plugins.in.ImportProcess.initializeStack(ImportProcess.java:520) > at loci.plugins.in.ImportProcess.execute(ImportProcess.java:147) > at loci.plugins.in.Importer.showDialogs(Importer.java:140) > at loci.plugins.in.Importer.run(Importer.java:76) > at loci.plugins.LociImporter.run(LociImporter.java:78) > at ij.IJ.runUserPlugIn(IJ.java:212) > at ij.IJ.runPlugIn(IJ.java:176) > at ij.Executer.runCommand(Executer.java:136) > at ij.Executer.run(Executer.java:65) > at java.lang.Thread.run(Thread.java:662) > > I am not familiar with computer programming language, so I am unsure what > this error means. Each one of my files have similar names but would I need > to change them to a more simple name for this to work? > > Kind Regards, > > Jessica > > On 26 January 2016 at 15:24, Curtis Rueden <[hidden email]> wrote: > > > Hi Jessica, > > > > > I am looking for help to write a simple macro to open different single > > > images in the same folder, combine them into a stack, and save the > > > stack under a different name in a different folder. > > > > Try this: > > > > * Press L for Command Finder > > * Check the "Close window after running command" option > > * Type "Record." and press enter to run the Plugins>Macros>Record... > > function > > * Press L again > > * Type "Bio-Formats", down arrow, enter to run the File > Import > > > Bio-Formats command > > * Choose one of your files and press OK. > > * Check the "Group files with similar names" option of the Bio-Formats > > Importer Options dialog box. > > * All your files should open as a single stack > > * Use the File > Save As menu to save the stack to the desired output > > format > > * Now look at your Recorder window. It contains your macro to repeat the > > process. (You can prune out the "Command Finder" lines; they are > > unnecessary for the macro to work.) > > > > Regards, > > Curtis > > > > On Tue, Jan 26, 2016 at 7:40 AM, Jessica Davis < > > [hidden email]> > > wrote: > > > > > Hello everyone, > > > > > > I am looking for help to write a simple macro to open different single > > > images in the same folder, combine them into a stack, and save the > stack > > > under a different name in a different folder. > > > > > > The images I want to combine have similar titles. For example: > > > "w000_t000_tt000" , "w000_t000_tt001" , "w000_t000_tt002"... and > > > "w001_t000_tt000" , "w001_t000_tt0001" , "w001_t000_tt002" ... > > > > > > Can this be done? > > > > > > Many thanks. > > > > > > Kind Regards, > > > > > > Jessica > > > > > > -- > > > > > > Jessica Davis MSc. > > > > > > Conway Institute of Biomolecular and Biomedical Research, > > > University College Dublin, > > > Belfield, Dublin 4. > > > > > > -- > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > > > -- > > Jessica Davis MSc. > > Conway Institute of Biomolecular and Biomedical Research, > University College Dublin, > Belfield, Dublin 4. > > Tel: +353857444220 > > -- > 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 |