Good evening,
Let's suppose I want to improve the speed of a method that only need the size (width/height) of an image (bmp, gif, jpg, png, tif) without completely open it. Is there's any way to do it with ImageJ ? ImagePlus imagePlus = new Opener().openImage(fileName); System.out.println(imagePlus.getWidth()); System.out.println(imagePlus.getHeight()); Thanks for your answer ? -- Thomas LEDUC |
Dear Thomas,
There's probably a better way, but here's what I've been doing to open images and take data from them without displaying them. This code is hacked from "Raw_File_Opener.java", that uses Java "swing". see: http://rsb.info.nih.gov/ij/plugins/raw-file-opener.html boolean show = false; fi_1.fileName = files_1[0].getName(); FileOpener fo_1 = new FileOpener(fi_1); IplusMyFile = fo_1.open(show); IprocMyProc = IplusMyFile.getProcessor(); I'd like to see what the experts say. Sincerely, Russell Thomas Leduc wrote: > Good evening, > Let's suppose I want to improve the speed of a method that only need the > size (width/height) > of an image (bmp, gif, jpg, png, tif) without completely open it. Is there's > any way to do it with > ImageJ ? > > ImagePlus imagePlus = new Opener().openImage(fileName); > System.out.println(imagePlus.getWidth()); > System.out.println(imagePlus.getHeight()); > > Thanks for your answer ? > > |
In reply to this post by Thomas Leduc
In a plugin, you can get the width and height of an image without
displaying it using ImagePlus imp = IJ.openImage(path); String title = imp.getTitle(); int width = imp.getWidth(); int height = imp.getHeight(); imp.close(); IJ.log(title+": "+width+"x"+height); or in a macro using setBatchMode(true); open(path); width = getWidth; height = getHeight; close(); print(getTitle+": "+width+"x"+height); With TIFF files, you can get the width and height without reading the pixel data using TiffDecoder td = new TiffDecoder(directory, name); FileInfo[] info=null; try { info = td.getTiffInfo(); } catch (IOException e) { IJ.error("TiffDecoder", ""+e); } if (info!=null) { String title = info[0].fileName; int width = info[0].width; int height = info[0].height; IJ.log(title+": "+width+"x"+height); } I do not know of an easy way to get the width and height of bmp, gif, jpg, png images without reading the pixel data. -wayne On Oct 4, 2007, at 5:25 PM, Thomas Leduc wrote: > Good evening, > Let's suppose I want to improve the speed of a method that only need > the > size (width/height) > of an image (bmp, gif, jpg, png, tif) without completely open it. Is > there's > any way to do it with > ImageJ ? > > ImagePlus imagePlus = new Opener().openImage(fileName); > System.out.println(imagePlus.getWidth()); > System.out.println(imagePlus.getHeight()); > > Thanks for your answer ? > > -- > Thomas LEDUC > |
In reply to this post by Thomas Leduc
Thomas,
Not sure exactly what you want to do (are you writing an imagej plugin, or just asking if imagej can do what you need for another application?), but consider imagemagick (imagemagick.org) which can be scripted. For example, if I use the "identify" command fromt the imagemagick package like such >>identify solids.png I get >>solids.png PNG 1023x791 1023x791+0+0 DirectClass 8-bit 83.6191kb which then can be parsed to return 1023 and 791 as x and y dimensions. just a thought . . . Jim ImageJ Interest Group <[hidden email]> wrote on 10/04/2007 05:25:01 PM: > Good evening, > Let's suppose I want to improve the speed of a method that > only need the > size (width/height) > of an image (bmp, gif, jpg, png, tif) without completely > open it. Is there's > any way to do it with > ImageJ ? > > ImagePlus imagePlus = new Opener().openImage(fileName); > System.out.println(imagePlus.getWidth()); > System.out.println(imagePlus.getHeight()); > > Thanks for your answer ? > > -- > Thomas LEDUC |
In reply to this post by Wayne Rasband
Hi Thomas,
Bio-Formats (http://www.loci.wisc.edu/ome/formats.html) can read image dimensions (and a lot of other metadata) without reading in actual image planes. If you put loci_tools.jar into your plugins folder, with ImageJ v1.39c or later, you can use the Bio-Formats Macro Extensions to grab the image dimensions really easily from all 50+ supported image formats. Here is an example macro that reports the width and height for a particular file: run("Bio-Formats Macro Extensions"); Ext.setId("/path/to/myfile.lif"); Ext.getSizeX(width); Ext.getSizeY(height); showMessage("Dimensions: " + width + " x " + height); Ext.close(); Or if you are writing a plugin, the sample plugin (Get_Dims.java) below will bring up a file chooser and report the width and height to you. Please let me know if you have any questions or issues. Cheers, Curtis --------------------------------- // Get_Dims.java import ij.IJ; import ij.io.OpenDialog; import ij.plugin.PlugIn; import java.io.IOException; import loci.formats.FormatException; import loci.formats.ImageReader; public class Get_Dims implements PlugIn { public void run(String arg) { OpenDialog od = new OpenDialog("Check file dimensions...", arg); String dir = od.getDirectory(); String name = od.getFileName(); if (dir == null || name == null) return; String id = dir + name; IJ.showStatus("Reading " + id); ImageReader reader = new ImageReader(); int width = -1, height = -1; try { reader.setId(id); width = reader.getSizeX(); height = reader.getSizeY(); reader.close(); } catch (FormatException exc) { IJ.error(exc.getMessage()); } catch (IOException exc) { IJ.error(exc.getMessage()); } IJ.showStatus(""); IJ.showMessage("Dimensions: " + width + " x " + height); } } On 10/5/07, Wayne Rasband <[hidden email]> wrote: > In a plugin, you can get the width and height of an image without > displaying it using > > ImagePlus imp = IJ.openImage(path); > String title = imp.getTitle(); > int width = imp.getWidth(); > int height = imp.getHeight(); > imp.close(); > IJ.log(title+": "+width+"x"+height); > > or in a macro using > > setBatchMode(true); > open(path); > width = getWidth; > height = getHeight; > close(); > print(getTitle+": "+width+"x"+height); > > With TIFF files, you can get the width and height without reading the > pixel data using > > TiffDecoder td = new TiffDecoder(directory, name); > FileInfo[] info=null; > try { > info = td.getTiffInfo(); > } catch (IOException e) { > IJ.error("TiffDecoder", ""+e); > } > if (info!=null) { > String title = info[0].fileName; > int width = info[0].width; > int height = info[0].height; > IJ.log(title+": "+width+"x"+height); > } > > I do not know of an easy way to get the width and height of bmp, gif, > jpg, png images without reading the pixel data. > > -wayne > > > On Oct 4, 2007, at 5:25 PM, Thomas Leduc wrote: > > > Good evening, > > Let's suppose I want to improve the speed of a method that only need > > the > > size (width/height) > > of an image (bmp, gif, jpg, png, tif) without completely open it. Is > > there's > > any way to do it with > > ImageJ ? > > > > ImagePlus imagePlus = new Opener().openImage(fileName); > > System.out.println(imagePlus.getWidth()); > > System.out.println(imagePlus.getHeight()); > > > > Thanks for your answer ? > > > > -- > > Thomas LEDUC > > > |
Hi,
Very interesting method but what is the license ? Thanks R1. 2007/10/6, Curtis Rueden <[hidden email]>: > Hi Thomas, > > Bio-Formats (http://www.loci.wisc.edu/ome/formats.html) can read image > dimensions (and a lot of other metadata) without reading in actual > image planes. > > If you put loci_tools.jar into your plugins folder, with ImageJ v1.39c > or later, you can use the Bio-Formats Macro Extensions to grab the > image dimensions really easily from all 50+ supported image formats. > Here is an example macro that reports the width and height for a > particular file: > > run("Bio-Formats Macro Extensions"); > Ext.setId("/path/to/myfile.lif"); > Ext.getSizeX(width); > Ext.getSizeY(height); > showMessage("Dimensions: " + width + " x " + height); > Ext.close(); > > Or if you are writing a plugin, the sample plugin (Get_Dims.java) > below will bring up a file chooser and report the width and height to > you. > > Please let me know if you have any questions or issues. > > Cheers, > Curtis > > --------------------------------- > // Get_Dims.java > > import ij.IJ; > import ij.io.OpenDialog; > import ij.plugin.PlugIn; > import java.io.IOException; > import loci.formats.FormatException; > import loci.formats.ImageReader; > > public class Get_Dims implements PlugIn { > public void run(String arg) { > OpenDialog od = new OpenDialog("Check file dimensions...", arg); > String dir = od.getDirectory(); > String name = od.getFileName(); > if (dir == null || name == null) return; > String id = dir + name; > IJ.showStatus("Reading " + id); > ImageReader reader = new ImageReader(); > int width = -1, height = -1; > try { > reader.setId(id); > width = reader.getSizeX(); > height = reader.getSizeY(); > reader.close(); > } > catch (FormatException exc) { IJ.error(exc.getMessage()); } > catch (IOException exc) { IJ.error(exc.getMessage()); } > IJ.showStatus(""); > IJ.showMessage("Dimensions: " + width + " x " + height); > } > } > > On 10/5/07, Wayne Rasband <[hidden email]> wrote: > > In a plugin, you can get the width and height of an image without > > displaying it using > > > > ImagePlus imp = IJ.openImage(path); > > String title = imp.getTitle(); > > int width = imp.getWidth(); > > int height = imp.getHeight(); > > imp.close(); > > IJ.log(title+": "+width+"x"+height); > > > > or in a macro using > > > > setBatchMode(true); > > open(path); > > width = getWidth; > > height = getHeight; > > close(); > > print(getTitle+": "+width+"x"+height); > > > > With TIFF files, you can get the width and height without reading the > > pixel data using > > > > TiffDecoder td = new TiffDecoder(directory, name); > > FileInfo[] info=null; > > try { > > info = td.getTiffInfo(); > > } catch (IOException e) { > > IJ.error("TiffDecoder", ""+e); > > } > > if (info!=null) { > > String title = info[0].fileName; > > int width = info[0].width; > > int height = info[0].height; > > IJ.log(title+": "+width+"x"+height); > > } > > > > I do not know of an easy way to get the width and height of bmp, gif, > > jpg, png images without reading the pixel data. > > > > -wayne > > > > > > On Oct 4, 2007, at 5:25 PM, Thomas Leduc wrote: > > > > > Good evening, > > > Let's suppose I want to improve the speed of a method that only need > > > the > > > size (width/height) > > > of an image (bmp, gif, jpg, png, tif) without completely open it. Is > > > there's > > > any way to do it with > > > ImageJ ? > > > > > > ImagePlus imagePlus = new Opener().openImage(fileName); > > > System.out.println(imagePlus.getWidth()); > > > System.out.println(imagePlus.getHeight()); > > > > > > Thanks for your answer ? > > > > > > -- > > > Thomas LEDUC > > > > > > -- Ingénieur de recherche Docteur en géographie, spécialité géomatique École Centrale de Nantes Institut de recherche en sciences et techniques de la ville http://www.irstv.cnrs.fr/ http://geosysin.iict.ch/irstv-trac/wiki http://r1.bocher.free.fr http://www.projet-sigle.org |
Hi Erwan,
Bio-Formats is open source software licensed under the LGPL, meaning it can be freely used as a library in any software, but modifications released to the public must also be open source. For further information, check these links: http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License http://www.oss-watch.ac.uk/resources/lgpl.xml http://www.gnu.org/licenses/lgpl.html -Curtis On 10/8/07, erwan bocher <[hidden email]> wrote: > Hi, > > Very interesting method but what is the license ? > > Thanks > > R1. > > > 2007/10/6, Curtis Rueden <[hidden email]>: > > Hi Thomas, > > > > Bio-Formats (http://www.loci.wisc.edu/ome/formats.html) can read image > > dimensions (and a lot of other metadata) without reading in actual > > image planes. > > > > If you put loci_tools.jar into your plugins folder, with ImageJ v1.39c > > or later, you can use the Bio-Formats Macro Extensions to grab the > > image dimensions really easily from all 50+ supported image formats. > > Here is an example macro that reports the width and height for a > > particular file: > > > > run("Bio-Formats Macro Extensions"); > > Ext.setId("/path/to/myfile.lif"); > > Ext.getSizeX(width); > > Ext.getSizeY(height); > > showMessage("Dimensions: " + width + " x " + height); > > Ext.close(); > > > > Or if you are writing a plugin, the sample plugin (Get_Dims.java) > > below will bring up a file chooser and report the width and height to > > you. > > > > Please let me know if you have any questions or issues. > > > > Cheers, > > Curtis > > > > --------------------------------- > > // Get_Dims.java > > > > import ij.IJ; > > import ij.io.OpenDialog; > > import ij.plugin.PlugIn; > > import java.io.IOException; > > import loci.formats.FormatException; > > import loci.formats.ImageReader; > > > > public class Get_Dims implements PlugIn { > > public void run(String arg) { > > OpenDialog od = new OpenDialog("Check file dimensions...", arg); > > String dir = od.getDirectory(); > > String name = od.getFileName(); > > if (dir == null || name == null) return; > > String id = dir + name; > > IJ.showStatus("Reading " + id); > > ImageReader reader = new ImageReader(); > > int width = -1, height = -1; > > try { > > reader.setId(id); > > width = reader.getSizeX(); > > height = reader.getSizeY(); > > reader.close(); > > } > > catch (FormatException exc) { IJ.error(exc.getMessage()); } > > catch (IOException exc) { IJ.error(exc.getMessage()); } > > IJ.showStatus(""); > > IJ.showMessage("Dimensions: " + width + " x " + height); > > } > > } > > > > On 10/5/07, Wayne Rasband <[hidden email]> wrote: > > > In a plugin, you can get the width and height of an image without > > > displaying it using > > > > > > ImagePlus imp = IJ.openImage(path); > > > String title = imp.getTitle(); > > > int width = imp.getWidth(); > > > int height = imp.getHeight(); > > > imp.close(); > > > IJ.log(title+": "+width+"x"+height); > > > > > > or in a macro using > > > > > > setBatchMode(true); > > > open(path); > > > width = getWidth; > > > height = getHeight; > > > close(); > > > print(getTitle+": "+width+"x"+height); > > > > > > With TIFF files, you can get the width and height without reading the > > > pixel data using > > > > > > TiffDecoder td = new TiffDecoder(directory, name); > > > FileInfo[] info=null; > > > try { > > > info = td.getTiffInfo(); > > > } catch (IOException e) { > > > IJ.error("TiffDecoder", ""+e); > > > } > > > if (info!=null) { > > > String title = info[0].fileName; > > > int width = info[0].width; > > > int height = info[0].height; > > > IJ.log(title+": "+width+"x"+height); > > > } > > > > > > I do not know of an easy way to get the width and height of bmp, gif, > > > jpg, png images without reading the pixel data. > > > > > > -wayne > > > > > > > > > On Oct 4, 2007, at 5:25 PM, Thomas Leduc wrote: > > > > > > > Good evening, > > > > Let's suppose I want to improve the speed of a method that only need > > > > the > > > > size (width/height) > > > > of an image (bmp, gif, jpg, png, tif) without completely open it. Is > > > > there's > > > > any way to do it with > > > > ImageJ ? > > > > > > > > ImagePlus imagePlus = new Opener().openImage(fileName); > > > > System.out.println(imagePlus.getWidth()); > > > > System.out.println(imagePlus.getHeight()); > > > > > > > > Thanks for your answer ? > > > > > > > > -- > > > > Thomas LEDUC > > > > > > > > > > > > -- > Ingénieur de recherche > Docteur en géographie, > spécialité géomatique > École Centrale de Nantes > Institut de recherche en sciences et techniques de la ville > http://www.irstv.cnrs.fr/ > http://geosysin.iict.ch/irstv-trac/wiki > http://r1.bocher.free.fr > http://www.projet-sigle.org > |
Free forum by Nabble | Edit this page |