We're Hiring!

discrepancy between original BMP and converted ome-tif

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

discrepancy between original BMP and converted ome-tif

Postby bhcho » Wed Nov 10, 2010 9:09 pm

Hi All,

I just confirmed there is difference in pixel values between original BMP and the convereted ome-tif images.
I used the bio-format library to convert the BMP files into ome-tif files.

When I look at those images by eyes, they look almost the same.
But when I compare those pixel values at the same locations, there are differences by 1~4 (not constantly). I was using Bio-format 2008 version in converting.
Is there any sort of round error? or Is there anything related to the BigEndian thing?

Best wishes,
BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: discrepancy between original BMP and converted ome-tif

Postby mlinkert » Wed Nov 10, 2010 9:57 pm

Hi BK,

I just confirmed there is difference in pixel values between original BMP and the convereted ome-tif images.
I used the bio-format library to convert the BMP files into ome-tif files.

When I look at those images by eyes, they look almost the same.
But when I compare those pixel values at the same locations, there are differences by 1~4 (not constantly). I was using Bio-format 2008 version in converting.


I would strongly recommend upgrading to 4.2.0, or waiting a couple of days and trying 4.2.1. There are many, many bugs that have been fixed since 2008, so with any luck this problem has been fixed as well.

If you see the same problem after upgrading, then the best thing to do is to send one of the original BMP files along with the exact steps you are using to convert the file (e.g. using 'bfconvert', using ImageJ, ...). If you are using your own code to convert the file, then it would help to have that code as well.

If you need a place to put files, just let me know and I can send you our SFTP server information.

Is there any sort of round error? or Is there anything related to the BigEndian thing?


I would only expect the pixel values to be different if you are saving the OME-TIFF file with a lossy compression type (JPEG or JPEG-2000). Otherwise, the pixel values should be the same.

Regards,
-Melissa
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin

Re: discrepancy between original BMP and converted ome-tif

Postby bhcho » Thu Nov 11, 2010 12:50 am

Hi Melissa,

Thanks.
Does it work if I just update the bioformat for my java code? (I'm afriad it does not work).

If not, could you please direct me to the link to the corresponding sample java code that converts other types of images to ome-tif images?
I was writing a converting java code based on the previous "ConvertToOmeTiff.java" sample code that uses bioformats 2008 version. Do you have the corresponding sample code that uses 4.2.0 version, rather than 2008 version?


Best,
BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: discrepancy between original BMP and converted ome-tif

Postby mlinkert » Thu Nov 11, 2010 2:07 am

Hi BK,

I was writing a converting java code based on the previous "ConvertToOmeTiff.java" sample code that uses bioformats 2008 version. Do you have the corresponding sample code that uses 4.2.0 version, rather than 2008 version?


The version of ConvertToOmeTiff.java that was released with 4.2.0 is here:

http://dev.loci.wisc.edu/trac/software/ ... eTiff.java

And the most recent version in our Subversion repository is here:

http://dev.loci.wisc.edu/trac/software/ ... eTiff.java

If those examples don't shed light on why 4.2.0 doesn't work with your code, then it would be very helpful if you could post your code so that we can see exactly where the problem might be.

Regards,
-Melissa
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin

Re: discrepancy between original BMP and converted ome-tif

Postby bhcho » Thu Nov 11, 2010 2:32 am

Thanks Mellisa,

I will try to update my code using the bio-format 4.2.0.
And could you please direct me to the documentation of the library? It looks those API functions have been changed a lot.

In the meanwhile, could you look at my old code (actually a part of my code) and tell me if there is anywhere to be fixed?

here is the part of my code that writes the ome-tif file.
thanks a lot in advance.

Code: Select all
          // this part is essential for writing a OME-TIFF file in 2008 version.
          ServiceFactory fac= new ServiceFactory();
          OMEXMLService serv = fac.getInstance(OMEXMLService.class);
          IMetadata omexmlMeta = serv.createOMEXMLMetadata();
          omexmlMeta.createRoot();
          String bigendian = pslidxmlparser.getBigEndian();
          Boolean tmp=null;
          if ( "true".equalsIgnoreCase(bigendian) ){
               tmp=Boolean.TRUE;
          } else {
               tmp=Boolean.FALSE;
          }
          omexmlMeta.setPixelsBigEndian(tmp, 0, 0); //setPixelsBigEndian, int imageIndex, int binDataIndex
          omexmlMeta.setPixelsDimensionOrder(pslidxmlparser.getDimensionOrder(), 0, 0);
          omexmlMeta.setPixelsPixelType(pslidxmlparser.getPixelType(), 0, 0);
         
          for (int c=0; c<Num_channel; c++){
               omexmlMeta.setLogicalChannelName(channelnames[c],0,c); //(String name, int imageIndex, int channelIndex
          }
         
          omexmlMeta.setPixelsSizeX(Integer.parseInt(pslidxmlparser.getSizeX()), 0, 0);
          omexmlMeta.setPixelsSizeY(Integer.parseInt(pslidxmlparser.getSizeY()), 0, 0);
          omexmlMeta.setPixelsSizeC(Integer.parseInt(pslidxmlparser.getSizeC()), 0, 0);
          omexmlMeta.setPixelsSizeZ(Integer.parseInt(pslidxmlparser.getSizeZ()), 0, 0);
          omexmlMeta.setPixelsSizeT(Integer.parseInt(pslidxmlparser.getSizeT()), 0, 0);
         
          writer.setMetadataRetrieve(omexmlMeta);
          writer.setId(savefile);

          // each image is a channel of the same image.
          for (int c=0; c<Num_channel; c++) {
                    byte[] plane = readers[c].openBytes(0);
                    writer.saveBytes(plane, 0, Boolean.TRUE,
                                     (c == Num_channel - 1));
          }
         
          writer.close();
          for (int i=0; i<Num_channel; i++){
               readers[i].close();
          }
         
             
          // OVERWRITE the OME-XML part
          TiffSaver saver = new TiffSaver(savefile);
          RandomAccessInputStream in = new RandomAccessInputStream(savefile);
          saver.overwriteComment(in, result);
          in.close();


where,
1. pslidxmlparser is an object that contains information of original image.
2. "bigendian" is a Boolean String of endianness, which is extracted from the original image by using
ImageReader.getCoreMetadata()[0].littleEndian
3. channelnames is String array of channel names
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: discrepancy between original BMP and converted ome-tif

Postby mlinkert » Thu Nov 11, 2010 4:09 pm

Hi BK,

And could you please direct me to the documentation of the library? It looks those API functions have been changed a lot.


The most recent Javadocs are available here:

http://dev.loci.wisc.edu:8080/job/LOCI/javadoc/

For the most part, the most recent versions of the developer documentation and example code are linked off of this page:

http://loci.wisc.edu/bio-formats/bio-fo ... va-library

In the meanwhile, could you look at my old code (actually a part of my code) and tell me if there is anywhere to be fixed?


Try something like this:

Code: Select all
              // this part is essential for writing a OME-TIFF file in 2008 version.
              ServiceFactory fac= new ServiceFactory();
              OMEXMLService serv = fac.getInstance(OMEXMLService.class);
              IMetadata omexmlMeta = serv.createOMEXMLMetadata();
              omexmlMeta.createRoot();
              String bigendian = pslidxmlparser.getBigEndian();
              Boolean tmp=null;
              if ( "true".equalsIgnoreCase(bigendian) ){
                   tmp=Boolean.TRUE;
              } else {
                   tmp=Boolean.FALSE;
              }
              omexmlMeta.setImageID("Image:0", 0);
              omexmlMeta.setPixelsID("Pixels:0", 0);
              omexmlMeta.setPixelsBinDataBigEndian(tmp, 0, 0); //setPixelsBigEndian, int imageIndex, int binDataIndex
              String dimensionOrder = pslidxmlparser.getDimensionOrder();
              DimensionOrder orderEnum = (DimensionOrder) new DimensionOrderEnumHandler().getEnumeration(dimensionOrder);
              omexmlMeta.setPixelsDimensionOrder(orderEnum, 0);
              omexmlMeta.setPixelsType(PixelType.fromString(pslidxmlparser.getPixelType()), 0);
             
              for (int c=0; c<Num_channel; c++){
                   omexmlMeta.setChannelID("Channel:0:" + c, 0, c);
                   omexmlMeta.setChannelName(channelnames[c],0,c); //(String name, int imageIndex, int channelIndex
              }
             
              omexmlMeta.setPixelsSizeX(new PositiveInteger(Integer.parseInt(pslidxmlparser.getSizeX())), 0);
              omexmlMeta.setPixelsSizeY(new PositiveInteger(Integer.parseInt(pslidxmlparser.getSizeY())), 0);
              omexmlMeta.setPixelsSizeC(new PositiveInteger(Integer.parseInt(pslidxmlparser.getSizeC())), 0);
              omexmlMeta.setPixelsSizeZ(new PositiveInteger(Integer.parseInt(pslidxmlparser.getSizeZ())), 0);
              omexmlMeta.setPixelsSizeT(new PositiveInteger(Integer.parseInt(pslidxmlparser.getSizeT())), 0);
             
              writer.setMetadataRetrieve(omexmlMeta);
              writer.setId(savefile);

              // each image is a channel of the same image.
              for (int c=0; c<Num_channel; c++) {
                        byte[] plane = readers[c].openBytes(0);
                        writer.saveBytes(c, plane);
              }
             
              writer.close();
              for (int i=0; i<Num_channel; i++){
                   readers[i].close();
              }
             
                 
              // OVERWRITE the OME-XML part
              TiffSaver saver = new TiffSaver(savefile);
              RandomAccessInputStream in = new RandomAccessInputStream(savefile);
              saver.overwriteComment(in, result);
              in.close();


Where PositiveInteger is in ome.xml.model.primitives, DimensionOrder and PixelType are in ome.xml.model.enums, and DimensionOrderEnumHandler is in ome.xml.model.enums.handlers.

Also, you may not need to overwrite the OME-XML at the end. As long as the writer is an OMETiffWriter (or an ImageWriter, and 'savefile' ends with '.ome.tiff' or '.ome.tif'), then the OME-XML corresponding to 'omexmlMeta' will be correctly written to the TIFF comment.

Regards,
-Melissa
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin

Re: discrepancy between original BMP and converted ome-tif

Postby bhcho » Thu Nov 11, 2010 6:26 pm

Thanks Melissa,

I'll try the code.

Also, you may not need to overwrite the OME-XML at the end. As long as the writer is an OMETiffWriter (or an ImageWriter, and 'savefile' ends with '.ome.tiff' or '.ome.tif'), then the OME-XML corresponding to 'omexmlMeta' will be correctly written to the TIFF comment.


And I was filling some ome-xml part (other than the minimum required elements), so I need to overwrite it.

Best,

BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: discrepancy between original BMP and converted ome-tif

Postby bhcho » Thu Nov 18, 2010 3:37 pm

Hi Melissa,

I tried to convert a BMP file to ome-tiff with the basic code from below, it still gives me the same result.
http://dev.loci.wisc.edu/trac/software/%20...%20eTiff.java

I can't attache the original image to here. could you tell me how I can send it to you?
please try to convert the BMP file and compare the pixel values.
for example, the pixel value from the original BMP file at x=100, y=125 is 155, but it is 127 at the same location from the converted ome-tif file.

when I look at the histogram of pixel values, it looks almost the same.
However, the minimum value is 19 for the original and 0 for the conveted one.
the others such as Mean, Max, StdDev, Mode, and # of pixels are exactly the same.

Best,
BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: discrepancy between original BMP and converted ome-tif

Postby mlinkert » Thu Nov 18, 2010 11:25 pm

Hi BK,

I can't attache the original image to here. could you tell me how I can send it to you?


I will send you our SFTP server details privately.

Regards,
-Melissa
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin

Re: discrepancy between original BMP and converted ome-tif

Postby mlinkert » Fri Nov 19, 2010 6:25 pm

Hi BK,

Thank you for sending a file.

please try to convert the BMP file and compare the pixel values.
for example, the pixel value from the original BMP file at x=100, y=125 is 155, but it is 127 at the same location from the converted ome-tif file.


How are you checking the pixel values? If I open ch_00.bmp in ImageJ, then zoom in to (100, 125) I see that the pixel value is 127 - see the attached screenshot. You may need to set the "Pixel Width" and "Pixel Height" properties to 1 in "Image > Properties..." in order to see the pixel coordinates. Note that I was testing with Bio-Formats 4.2.1 and ImageJ 1.43u.

I then converted ch_00.bmp to OME-TIFF and checked the MD5 of the image from the original file against the MD5 of the image in the converted file using this code:

Code: Select all
import java.security.MessageDigest;
import loci.common.DataTools;
import loci.formats.ImageReader;

public class MD5Test {
  public static void main(String[] args) throws Exception {
    ImageReader reader = new ImageReader();
    MessageDigest md = MessageDigest.getInstance("MD5");

    for (String arg : args) {
      reader.setId(arg);
      byte[] firstPlane = reader.openBytes(0);

      md.reset();
      md.update(firstPlane);
      String digest = DataTools.bytesToHex(md.digest());
      System.out.println("MD5 for plane #0 of " + arg + " = " + digest);
      reader.close();
    }
  }
}


Running the above code produced this output:

Code: Select all
melissa@medusa:~$ java MD5Test ch_00.bmp ch_00.ome.tiff
Reading bitmap header
Populating metadata
MD5 for plane #0 of ch_00.bmp = d048c3b6f089fc6734f1d1f0ac649b64
Reading IFDs
Populating metadata
MD5 for plane #0 of ch_00.ome.tiff = d048c3b6f089fc6734f1d1f0ac649b64


In other words, the pixel data is identical.

So, can you please verify that the pixel values you mentioned previously are correct and that you see the same output as I do when running the above code?

Regards,
-Melissa
Attachments
ch_00-screenshot.png
ch_00-screenshot.png (23.19 KiB) Viewed 4589 times
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin

Next

Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests