Getting the scale

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting the scale

Cspr
Dear user,

How do you get the scale of an image? For instance when you open an image taken with a microscope the meta-data displayed just above the image can say something like "36.74x36.74 micron" followed by (512 x 512 pixels). How can you get the micron information from inside java i.e. how do I get 36.74 or some magnitude of it returned from Java? I've tried the calibration for the image but no method seems to return it. Any suggestions?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

Julian Cooper
Hi Cspr,

Where cal is a declared Calibration object and imp the ImagePlus object of
interest use:

        cal = imp.getCalibration();
        x = cal.pixelWidth; //x contains the pixel width in units
        y = cal.pixelHeight; //y contains the pixel height in units
        z = cal.pixelDepth; //z contains the pixel (voxel) depth in units

if you need the name of the unit (e.g. micron) then ij.measure.getUnit()
returns the singular form as a string and ij.measure.getUnits() the plural.

Hope this helps,

Julian

> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On
> Behalf Of Cspr
> Sent: 19 April 2010 22:00
> To: [hidden email]
> Subject: Getting the scale
>
>
> Dear user,
>
> How do you get the scale of an image? For instance when you
> open an image
> taken with a microscope the meta-data displayed just above
> the image can say
> something like "36.74x36.74 micron" followed by (512 x 512
> pixels). How can
> you get the micron information from inside java i.e. how do I
> get 36.74 or
> some magnitude of it returned from Java? I've tried the
> calibration for the
> image but no method seems to return it. Any suggestions?
>
> Thanks
> --
> View this message in context:
> http://n2.nabble.com/Getting-the-scale-tp4927899p4927899.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

Cspr
Thank you for your suggestion.

I might have mislead you slightly in my formulation of the question. See what I actually want is the scale or the ratio of pixels to microns. Using the cal.pixelwidth and similar calls simply returns 1.0 as the image IS in pixels. However I want that information in microns, hence I need to know the number of microns to pixels or vice-versa.

When I open an image in ImageJ Fiji and run Analyze -> Set Scale it gives me a Distance in Pixels and it is THAT value I would so dearly like, but apparently no call within ImageJ allows me to extract either

A) The microns of the image shown in the header of the image as e.g. 36.95x36.95 microns (512x512); 8-bit; 256K - i.e.
B) The Distance in Pixels

So from Java I would like to either get the Distance in Pixels or the micron number (in the above case that would be 36.95).

I'm honestly baffled why it is so difficult to get that information.
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

Julian Cooper
Sorry if I misunderstood,

I'm puzzled as well. If your imagewindow displays 36.95x36.95 microns
(512x512) in the subtitle then the image must be scaled, in which case the
cal.pixelWidth etc. will not return 1.0. It should return something like
0.07217 (i.e. 36.95/512). Only if the image has not been scaled then it will
return 1.0 pixels.

The values in the subtitle of the imagewindow are calculated by ImageJ using
imp.getWidth()*cal.pixelWidth and similar. The source can been seen at
http://rsbweb.nih.gov/ij/developer/source/ij/gui/ImageWindow.java.html
(createSubtitle() method).

To scale the image in java you would need to calculate the appropriate
pixelWidth etc and assign it to cal.pixelWidth etc., as well as using the
setUnit() method (in ij.measure.Calibration) to set the name of the unit.

Kind regards,

Julian

> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On
> Behalf Of Cspr
> Sent: 19 April 2010 23:28
> To: [hidden email]
> Subject: Re: Getting the scale
>
>
> Thank you for your suggestion.
>
> I might have mislead you slightly in my formulation of the
> question. See
> what I actually want is the scale or the ratio of pixels to
> microns. Using
> the cal.pixelwidth and similar calls simply returns 1.0 as
> the image IS in
> pixels. However I want that information in microns, hence I
> need to know the
> number of microns to pixels or vice-versa.
>
> When I open an image in ImageJ Fiji and run Analyze -> Set
> Scale it gives me
> a Distance in Pixels and it is THAT value I would so dearly like, but
> apparently no call within ImageJ allows me to extract either
>
> A) The microns of the image shown in the header of the image as e.g.
> 36.95x36.95 microns (512x512); 8-bit; 256K - i.e.
> B) The Distance in Pixels
>
> So from Java I would like to either get the Distance in
> Pixels or the micron
> number (in the above case that would be 36.95).
>
> I'm honestly baffled why it is so difficult to get that information.
> --
> View this message in context:
> http://n2.nabble.com/Getting-the-scale-tp4927899p4928293.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

Cspr
Thank you again for your suggestion.

This just leaves one, rather interesting, quetion. How do you calculate the pixelWidth? It seems that the ScaleDialog.java file computes the distance (i.e. the pixel to micron ratio) as

measured = ((Line)roi).getRawLength();
length = IJ.d2s(measured, 2);

where roi is the getRoi method called on the image. I use the read_image example from
https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/utils/Read_Image.java

to read an LIF file, but extracting a random image from that routine and displaying it returns a null when trying to use the imp.getRoi method. Creating a line and setting that as the ROI does nothing either. So i'm still very much troubled by this.
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

Cspr
I thought it might be better if I stated the problem in its complete form.

So I have an LIF file. In such a file is number of series and each series consists of a number of slices and each slice consist of three images. Each slice in each series are taken with the same micron resolution, but slices in other series within the same LIF file might have a different micron resolution.

What i've been doing in my, admittedly naive, approach was to use ImageJ Fiji to get the scale for the first series (using Analyze -> Set scale...), and just hardcode that value in Java and on each image using the IJ.run(image, "Set scale", "bla bla") where "bla bla would be something like "distance=14.591" etc.

This works for the series from which I used ImageJ Fiji to get the scale. However obviously when chaging series the scale is NOT necessarily correct anymore. So the problem is how to calculate the distance/scale on a series to series basis?
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

ctrueden
Hi everyone,

Here is a message from Melissa Linkert regarding retrieval of physical
dimension size metadata. The code she lists below should work regardless of
file format, as long as the information is actually present in the file. If
not, please let us know and we will investigate the issue.

To assign the metadata to an ImagePlus object, you can use the
ImagePlus.setCalibration(Calibration) method. Or you can read your ImagePlus
using the Bio-Formats Importer plugin, which should automatically set the
calibration as appropriate. (And an improved API for doing so from Java is
coming soon.)

-Curtis

On Sun, Apr 25, 2010 at 3:32 PM, Melissa Linkert <
[hidden email]> wrote:

> Here is a simple example of how to retrieve the size of a pixel in microns:
>
> // ----
> ImageProcessorReader r = new ImageProcessorReader(new ChannelSeparator());
> MetadataStore store = MetadataTools.createOMEXMLMetadata();
> r.setMetadataStore(store);
> r.setId("/path/to/file");
> MetadataRetrieve retrieve = MetadataTools.asRetrieve(r.getMetadataStore());
> for (int series=0; series<r.getSeriesCount(); series++) {
>  Double pixelWidth = retrieve.getDimensionsPhysicalSizeX(series, 0);
> // width of one pixel in microns
>  Double pixelHeight = retrieve.getDimensionsPhysicalSizeY(series, 0);
>  // height of one pixel in microns
> }
> r.close();
> // ----
>
> Note that MetadataStore and MetadataRetrieve are in the
> loci.formats.meta package, and MetadataTools is in the loci.formats
> package.  Also, MetadataRetrieve provides access to a lot more
> metadata than just the pixel sizes; if you are interested in
> retrieving additional metadata, I would recommend looking at the
> MetadataRetrieve Javadoc:
>
>
> http://hudson.openmicroscopy.org.uk/job/LOCI/javadoc/loci/formats/meta/MetadataRetrieve.html
>
> If you have any additional questions, please let us know.
>

On Tue, Apr 20, 2010 at 9:08 AM, Cspr <[hidden email]> wrote:

> Thank you again for your suggestion.
>
> This just leaves one, rather interesting, quetion. How do you calculate the
> pixelWidth? It seems that the ScaleDialog.java file computes the distance
> (i.e. the pixel to micron ratio) as
>
> measured = ((Line)roi).getRawLength();
> length = IJ.d2s(measured, 2);
>
> where roi is the getRoi method called on the image. I use the read_image
> example from
>
> https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/utils/Read_Image.java
>
> to read an LIF file, but extracting a random image from that routine and
> displaying it returns a null when trying to use the imp.getRoi method.
> Creating a line and setting that as the ROI does nothing either. So i'm
> still very much troubled by this.
>

On Tue, Apr 20, 2010 at 9:43 AM, Cspr <[hidden email]> wrote:

> I thought it might be better if I stated the problem in its complete form.
>
> So I have an LIF file. In such a file is number of series and each series
> consists of a number of slices and each slice consist of three images. Each
> slice in each series are taken with the same micron resolution, but slices
> in other series within the same LIF file might have a different micron
> resolution.
>
> What i've been doing in my, admittedly naive, approach was to use ImageJ
> Fiji to get the scale for the first series (using Analyze -> Set scale...),
> and just hardcode that value in Java and on each image using the
> IJ.run(image, "Set scale", "bla bla") where "bla bla would be something
> like
> "distance=14.591" etc.
>
> This works for the series from which I used ImageJ Fiji to get the scale.
> However obviously when chaging series the scale is NOT necessarily correct
> anymore. So the problem is how to calculate the distance/scale on a series
> to series basis?
>
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

smfmazz
In reply to this post by Julian Cooper
Hi All,
Excuse me for my english. I take advantage of this topic. I want get the distance inter-pixel in mm... How can i make? Can i use the method get calibration and the method get unit?
If i have a stack, how i get the distance inter-slice (mm) ?  
Thanks a lot
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

Glen MacDonald-2
Well... to begin, how were the images collected, and in what file format were they saved? Have the images been converted from the original format into something else such as TIFF?  Most acquisition software will record the lateral and axial dimensions into the file.  what do you see in the Image>Properties or Image>Get Info... windows?
Opening the files with the LOCI plugin may present spatial information not accessible by the standard ImageJ opener.

Did you collect them, do you have access to the instrument?   If you know the lens, zoom, box size (if confocal), you could place a ruler or stage micrometer on the microscope and collect an image.  then measure the number of pixels per mm with imageJ. Details are in the documentation for  Analyze>Set Scale.  Alternatively, just setting up the instrument to match the collection settings may display the lateral scale.
If the axial scale cannot be extracted from the metadata, then the best you can do is estimate by comparison with some images collected while actually writing down the capture parameters.  

Look at the Imagej documentation    http://imagej.nih.gov/ij/docs/

Good luck,
Glen
Glen MacDonald
Core for Communication Research
Virginia Merrill Bloedel Hearing Research Center
Box 357923
University of Washington
Seattle, WA 98195-7923  USA
(206) 616-4156
[hidden email]








On Oct 12, 2010, at 4:17 AM, smfmazz wrote:

> Hi All,
> Excuse me for my english. I take advantage of this topic. I want get the
> distance inter-pixel in mm... How can i make? Can i use the method get
> calibration and the method get unit?
> If i have a stack, how i get the distance inter-slice (mm) ?  
> Thanks a lot
> --
> View this message in context: http://imagej.588099.n2.nabble.com/Getting-the-scale-tp4927899p5626285.html
> Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Getting the scale

smfmazz
Le immagini sono DICOM file. Si, con l'opzione"show info" vengono visualizzati questi valori, ma vorrei ottenerli con dei metodi java, per costruire un plugin. Per il momento comunque posso utilizzare la funzione "show info". Grazie per l'aiuto!