Login  Register

Re: File formats and pixel size

Posted by Gabriel Landini on Jun 03, 2021; 7:29pm
URL: http://imagej.273.s1.nabble.com/File-formats-and-pixel-size-tp5024686p5024693.html

Hello Aleksandr,

On Thursday, 3 June 2021 17:49:21 BST Aleksandr Mironov wrote:
> I will ask it in different way:
> 1) Is it true that ImageJ reads pixel size from dpi field, meaning that it
> has quite clumsy compatibility with other scientific programs?

I do not think so. IJ seems to store the values in the right place. There is no "dpi field", but these 'baseline' tags:

Tiff tags 282 (TIFFTAG_XRESOLUTION), 283 (TIFFTAG_YRESOLUTION) and 296 (TIFFTAG_RESOLUTIONUNIT)

The pertinent bit, I think, in TiffEncoder.java is:

if (fi.unit!=null && fi.pixelWidth!=0 && fi.pixelHeight!=0) {
        writeEntry(out, TiffDecoder.X_RESOLUTION, 5, 1, tagDataOffset);
        writeEntry(out, TiffDecoder.Y_RESOLUTION, 5, 1, tagDataOffset+8);
        tagDataOffset += SCALE_DATA_SIZE;
        int unit = 1;
        if (fi.unit.equals("inch"))
                unit = 2;
        else if (fi.unit.equals("cm"))
                unit = 3;
        writeEntry(out, TiffDecoder.RESOLUTION_UNIT, 3, 1, unit);
}
 
Note that the TIFF reference says: "It is not mandatory that the image be actually displayed or printed at the size implied by this parameter. It is up to the application to use this information as it wishes." The 50nm image anecdote is most likely due to Word wrongly assuming that 'image resolution' implies the printer 'output size'.

But the important point is that storing metadata in a private tag does not make it automagically "a standard" so all other programs *know* what to do with it. Private tags are a "standard way" for software authors to extend the format and store and retrieve whatever they want to put in there. Baseline tags should be interpreted correctly by all other programs, but it would be naive to expect the same for private tags because there is no way to know in advance what another software might have put in there. The tiff reader has to implement the recognition of the new tag and what it contains (and do something with that contents).

That being said, it possible to write a file reader that overrides the baseline tags if the private Tiff tag 34683 exists and use its data instead. As far as I understand it, the company implemented it about 6 yrs ago? (according to this OME bug report https://trac.openmicroscopy.org/ome/ticket/12743  ) so no surprise it has not been implemented widely if this was the first time that the issue has been raised.

I see that Herbie has just replied about this, too.

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html