I have a Bio-formats macro that opens up my Nikon Elements AVI files (which has an incorrect FPS header) and then saves them as uncompressed AVI with 15FPS. the input and output files are the same size, however my input is a grayscale image and the output is somehow being converted as a red image (perhaps an 8-bit image with Red LUT?). I have experimented with different kinds of image modes and hyperstacks, but this is as close as I have gotten. I can supply a small sample (input and output) if that would be helpful. This whole thing is because my Nikon Elements (AVI capture) always saves the files with 100FPS. The objective of this macro is to produce a file with the correct 15FPS in the header, a prerequisite for analyzing the movie with some other software. Is there a way to edit the header information directly without opening the file? Thanks for your assistance Chris // start Macro // batch process to re-header the .AVI files captured by April on the Nikon Elements // hacked together from by crichie on 09-08-10. // bfOpenAsHyperstack.txt Written by Wayne Rasband // and another macro from a forum post by Dr K.R. Straatman requires("1.41c"); /// /// dir1 = getDirectory("Choose Source Directory "); list = getFileList(dir1); dir2 = dir1+"analysed"+File.separator; File.makeDirectory(dir2); for (f=0; f<list.length; f++) { if (File.isDirectory(dir1+list[f])){} else{ path = dir1+list[f]; if (endsWith(path, ".db")){} else{ name = list[f]; run("Bio-Formats Macro Extensions"); Ext.setId(path); Ext.getCurrentFile(file); Ext.getSizeX(sizeX); Ext.getSizeY(sizeY); Ext.getSizeC(sizeC); Ext.getSizeZ(sizeZ); Ext.getSizeT(sizeT); Ext.getImageCount(n); setBatchMode(true); for (i=0; i<n; i++) { showProgress(i, n); Ext.openImage("plane "+i, i); if (i==0) stack = getImageID; else { run("Copy"); close; selectImage(stack); run("Add Slice"); run("Paste"); } } rename(name); if (nSlices>1) { Stack.setDimensions(sizeC, sizeZ, sizeT); if (sizeC>1) { if (sizeC==3&&sizeC==nSlices) mode = "Composite"; else mode = "Color"; run("Make Composite", "display="+mode); } } //run("AVI... ", "compression=Uncompressed frame=15 save="+path+"_15fps.avi"); newname = dir2 +"\\"+ name +"_15fps.avi"; print (newname); run("AVI... ", "compression=Uncompressed frame=15 save="+ dir2 +"\\"+ name +"_15fps.avi"); } setBatchMode(false); // Ext.close(); //remming this out to see if verbose error list goes away. close(); } } /// /// // end macro |
Hi Chris,
What program are you using for viewing the AVI? I've had this happen when viewing a file using VLC Media Player. So, you could try a different program and see if it is different. Also, are you sure that the images are greyscale? If your camera is colour, then you will have RGB images. In this case, you should convert to greyscale in ImageJ first and then create the AVI. I'm really sorry if this is an obvious comment but I have had people previously having issues with printing apparently greyscale images that are actually still in RGB format. They often print out green. If you just want to change speed/size, you could try just using VirtualDub. It's a freeware and I find it quite handy for compressing large AVI files. You can find it here: http://www.virtualdub.org/ Kind regards, Jacqui Jacqueline Ross Biomedical Imaging Microscopist Biomedical Imaging Research Unit School of Medical Sciences Faculty of Medical & Health Sciences The University of Auckland Private Bag 92019 Auckland, NEW ZEALAND Tel: 64 9 373 7599 Ext 87438 Fax: 64 9 373 7484 http://www.fmhs.auckland.ac.nz/sms/biru/ -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Chris Richie Sent: Thursday, 9 September 2010 8:18 a.m. To: [hidden email] Subject: ImageJ is saving my grayscale AVI files as RED? I have a Bio-formats macro that opens up my Nikon Elements AVI files (which has an incorrect FPS header) and then saves them as uncompressed AVI with 15FPS. the input and output files are the same size, however my input is a grayscale image and the output is somehow being converted as a red image (perhaps an 8-bit image with Red LUT?). I have experimented with different kinds of image modes and hyperstacks, but this is as close as I have gotten. I can supply a small sample (input and output) if that would be helpful. This whole thing is because my Nikon Elements (AVI capture) always saves the files with 100FPS. The objective of this macro is to produce a file with the correct 15FPS in the header, a prerequisite for analyzing the movie with some other software. Is there a way to edit the header information directly without opening the file? Thanks for your assistance Chris // start Macro // batch process to re-header the .AVI files captured by April on the Nikon Elements // hacked together from by crichie on 09-08-10. // bfOpenAsHyperstack.txt Written by Wayne Rasband // and another macro from a forum post by Dr K.R. Straatman requires("1.41c"); /// /// dir1 = getDirectory("Choose Source Directory "); list = getFileList(dir1); dir2 = dir1+"analysed"+File.separator; File.makeDirectory(dir2); for (f=0; f<list.length; f++) { if (File.isDirectory(dir1+list[f])){} else{ path = dir1+list[f]; if (endsWith(path, ".db")){} else{ name = list[f]; run("Bio-Formats Macro Extensions"); Ext.setId(path); Ext.getCurrentFile(file); Ext.getSizeX(sizeX); Ext.getSizeY(sizeY); Ext.getSizeC(sizeC); Ext.getSizeZ(sizeZ); Ext.getSizeT(sizeT); Ext.getImageCount(n); setBatchMode(true); for (i=0; i<n; i++) { showProgress(i, n); Ext.openImage("plane "+i, i); if (i==0) stack = getImageID; else { run("Copy"); close; selectImage(stack); run("Add Slice"); run("Paste"); } } rename(name); if (nSlices>1) { Stack.setDimensions(sizeC, sizeZ, sizeT); if (sizeC>1) { if (sizeC==3&&sizeC==nSlices) mode = "Composite"; else mode = "Color"; run("Make Composite", "display="+mode); } } //run("AVI... ", "compression=Uncompressed frame=15 save="+path+"_15fps.avi"); newname = dir2 +"\\"+ name +"_15fps.avi"; print (newname); run("AVI... ", "compression=Uncompressed frame=15 save="+ dir2 +"\\"+ name +"_15fps.avi"); } setBatchMode(false); // Ext.close(); //remming this out to see if verbose error list goes away. close(); } } /// /// // end macro -- View this message in context: http://imagej.588099.n2.nabble.com/ImageJ-is-saving-my-grayscale-AVI-fil es-as-RED-tp5512203p5512203.html Sent from the ImageJ mailing list archive at Nabble.com. |
In reply to this post by Chris Richie
Hi Chris,
the input and output files are the same size, however my input is a > grayscale image and the output is somehow being converted as a red image > (perhaps an 8-bit image with Red LUT?). > Your macro contains a code snippet that colorizes the images when there is more than one channel: if (sizeC>1) { > if (sizeC==3&&sizeC==nSlices) mode = "Composite"; > else mode = "Color"; > run("Make Composite", "display="+mode); > } > So if as Jacqui Ross suggests your AVIs are actually stored in RGB format, this code would be invoked. One option would be to change mode to always be "Grayscale" which should eliminate the issue regardless of your input data. Note also that your macro is vastly more complicated than you need merely to convert images. You can start the Macro Recorder, open an AVI as a hyperstack using Bio-Formats, and then save it back to disk. The recorder will then contain a very short macro you can adapt to batch process multiple AVIs in a loop without needing to use the Bio-Formats Macro Extensions. HTH, Curtis On Wed, Sep 8, 2010 at 3:18 PM, Chris Richie <[hidden email]> wrote: > I have a Bio-formats macro that opens up my Nikon Elements AVI files (which > has an incorrect FPS header) and then saves them as uncompressed AVI with > 15FPS. > > the input and output files are the same size, however my input is a > grayscale image and the output is somehow being converted as a red image > (perhaps an 8-bit image with Red LUT?). > > I have experimented with different kinds of image modes and hyperstacks, > but > this is as close as I have gotten. > > I can supply a small sample (input and output) if that would be helpful. > > This whole thing is because my Nikon Elements (AVI capture) always saves > the > files with 100FPS. The objective of this macro is to produce a file with > the correct 15FPS in the header, a prerequisite for analyzing the movie > with > some other software. Is there a way to edit the header information > directly > without opening the file? > > > Thanks for your assistance > Chris > > // start Macro > > // batch process to re-header the .AVI files captured by April on the Nikon > Elements > // hacked together from by crichie on 09-08-10. > // bfOpenAsHyperstack.txt Written by Wayne Rasband > // and another macro from a forum post by Dr K.R. Straatman > > > requires("1.41c"); > /// > /// > > dir1 = getDirectory("Choose Source Directory "); > list = getFileList(dir1); > dir2 = dir1+"analysed"+File.separator; > File.makeDirectory(dir2); > for (f=0; f<list.length; f++) > { > > if (File.isDirectory(dir1+list[f])){} > else{ > > path = dir1+list[f]; > if (endsWith(path, ".db")){} > else{ > name = list[f]; > > run("Bio-Formats Macro Extensions"); > Ext.setId(path); > Ext.getCurrentFile(file); > Ext.getSizeX(sizeX); > Ext.getSizeY(sizeY); > Ext.getSizeC(sizeC); > Ext.getSizeZ(sizeZ); > Ext.getSizeT(sizeT); > Ext.getImageCount(n); > > setBatchMode(true); > for (i=0; i<n; i++) { > showProgress(i, n); > Ext.openImage("plane "+i, i); > if (i==0) > stack = getImageID; > else { > run("Copy"); > close; > selectImage(stack); > run("Add Slice"); > run("Paste"); > } > } > > rename(name); > if (nSlices>1) { > Stack.setDimensions(sizeC, sizeZ, sizeT); > if (sizeC>1) { > if (sizeC==3&&sizeC==nSlices) mode = "Composite"; > else mode = "Color"; > run("Make Composite", "display="+mode); > } > } > //run("AVI... ", "compression=Uncompressed frame=15 > save="+path+"_15fps.avi"); > > newname = dir2 +"\\"+ name +"_15fps.avi"; > print (newname); > > run("AVI... ", "compression=Uncompressed frame=15 save="+ dir2 +"\\"+ name > +"_15fps.avi"); > > > } > setBatchMode(false); > > // Ext.close(); //remming this out to see if verbose error list goes away. > > close(); > } > } > /// > /// > > // end macro > -- > View this message in context: > http://imagej.588099.n2.nabble.com/ImageJ-is-saving-my-grayscale-AVI-files-as-RED-tp5512203p5512203.html > Sent from the ImageJ mailing list archive at Nabble.com. > |
In reply to this post by Chris Richie
Thanks for all your comments so far, I have made some progress with my problem. The movies that I am processing turned out to be RBG-type, they just "look" grayscale because they are brightfield images. I still require the Bio-formats importer to open them properly in ImageJ because of the (header-related?) bug in the Nikon Elements software. Right now, "messy/inefficient code" aside, my macro is working to open and process the files I need. I have very little programming training, just one course in C++ 15 years ago. My future effort will be to make it more memory and processing time efficient. Thanks chris most recent version: // batch process to re-header the .AVI files captured by April on the Nikon Elements // by crichie on 09-10-10. // Taken from bfOpenAsHyperstack.txt Written by Wayne Rasband // and another macro from a forum post by Dr K.R. Straatman requires("1.44"); /// /// dir1 = getDirectory("Choose Source Directory "); list = getFileList(dir1); dir2 = dir1+"converted"+File.separator; File.makeDirectory(dir2); for (f=0; f<list.length; f++) { if (File.isDirectory(dir1+list[f])){} else{ path = dir1+list[f]; if (endsWith(path, ".db")){} else{ name = list[f]; // begin timestamp_b getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour_b, minute_b, second_b, msec); // end timestamp_b // begin name without extension fix index = lastIndexOf(name, "."); if (index!=-1) name = substring(name, 0, index); print("Conversion has started for " +name +"."); // end name without extension fix run("Bio-Formats Macro Extensions"); Ext.setId(path); Ext.getCurrentFile(file); Ext.getSizeX(sizeX); Ext.getSizeY(sizeY); Ext.getSizeC(sizeC); Ext.getSizeZ(sizeZ); Ext.getSizeT(sizeT); Ext.getImageCount(n); setBatchMode(true); for (i=0; i<n; i++) { showProgress(i, n); Ext.openImage("plane "+i, i); if (i==0) stack = getImageID; else { run("Copy"); close; selectImage(stack); run("Add Slice"); run("Paste"); } } rename(name +"_hs"); if (nSlices>1) { Stack.setDimensions(sizeC, sizeZ, sizeT); if (sizeC>1) { if (sizeC==3&&sizeC==nSlices) mode = "Composite"; else mode = "Color"; run("Make Composite", "display="+mode); } } // setBatchMode(false); // begin - to reduce the hyperstack to apparently grayscale (but RGB color format). run("Reduce Dimensionality...", " frames keep"); run("Grays"); run("RGB Color"); // end - to reduce the hyperstack to apparently grayscale (but RGB color format). run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +".avi"); print (name +" has been converted to 15fps and saved."); rename(name+".avi"); selectWindow(name +"_hs"); close(); // this does not need to be open anymore // begin to split movies if (sizeT <= 4500) { print(name +" is less than or equal to 5 minutes and will not be split."); } else { print("The file is greater than 5 minutes and will be split."); print("This macro is currently set to discard frames after 10 minutes."); selectWindow(name +".avi"); run("Duplicate...", "title=" +name +"-1.avi duplicate range=1-4500"); run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +"-1.avi"); selectWindow(name +".avi"); run("Duplicate...", "title=" +name +"-2.avi duplicate range=4501-9000"); run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +"-2.avi"); /// remove these remarks to gain another 5 minutes of data (minutes 11 - 15). // selectWindow(name +".avi"); // run("Duplicate...", "title=" +name +"-3.avi duplicate range=9001-13500"); // run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +"-3.avi"); print("Chunking for " +name +" is complete."); } // end to split movies. getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour_e, minute_e, second_e, msec); elapsed = ((minute_e - minute_b)*60) + (second_e - second_b); print("Time elapsed = " +elapsed +" sec."); print(""); // an empty space line. } //setBatchMode(false); //remmed out to get the upstream files visible // Ext.close(); //remming this out to see if verbose error list goes away. // setBatchMode(false); } } /// /// |
Free forum by Nabble | Edit this page |