Login  Register

Re: Getting the scale

Posted by ctrueden on Apr 26, 2010; 9:36pm
URL: http://imagej.273.s1.nabble.com/Getting-the-scale-tp3686642p3686651.html

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?
>