Different intensity values?

Hi,

I just bumped into another trouble and would like to ask for your help.

There are three ways to read the intensity value of an image:

  • Using the Java Built in library ImageIO, ImageReader, …, etc.

  • Using ImageJ by Bio-format (IFormatReader, BufferedImageReader,…, etc)

  • Using Matlab

    I found that the intensity values obtained from method 1 and 3 are identical while a slight difference from method 2. Following is an example. Does it make sense ? If so, what is the reason for the difference ?

    Method 1 (Pure Java) 2 (ImageJ) 3 (Matlab)

    [128,128] 33 33 49
    [128,129] 38 36 56
    [129,129] 42 37 62
    [129,128] 35 36 52

    Max 193 193 286
    Min 0 0 0

And this is how I get the pixel value by bioformat:

IFormatReader imgReader = new ImageReader();

imgReader.setMetadataStore(MetadataTools.createOMEXMLMetadata());
imgReader.setId(filePath);

BufferedImageReader buffImgReader = new BufferedImageReader(imgReader);
BufferedImage buffImg = buffImgReader.openImage(64);

IJ.log("[128,128] = " + buffImg.getRaster().getSample(128,128, 0));
IJ.log("[128,129] = " + buffImg.getRaster().getSample(128,129, 0));
IJ.log("[129,129] = " + buffImg.getRaster().getSample(129,129, 0));
IJ.log("[129,128] = " + buffImg.getRaster().getSample(129,128, 0));

Thanks~~~~

Hi @blueclowd,

could you please verify that behavior with an ImageJ sample image and provide a minimum working example (as indicated by @imagejan in the other thread)?

Best,
Stefan

Hi Stelfrich,

Here is the example of Method 2., case 1 using the default ImagePlus, case 2 using the bioformat. Both the two cases give the value = [33,36,37,36], which is different from Method 1 and Method 3. Any suggestions?? Thanks.

     public int setup(String arg, ImagePlus imgPlus)
     {

        IJ.log("setup()...");

        // Case 1: by default ImagePlus
        imgPlus.setSlice(65);

        ImageProcessor imgProcessor = imgPlus.getProcessor();

        IJ.log("Case 1 = " + imgProcessor.get(128, 128));
        IJ.log("Case 1 = " + imgProcessor.get(129, 128));
        IJ.log("Case 1 = " + imgProcessor.get(129, 129));
        IJ.log("Case 1 = " + imgProcessor.get(129, 128));


        // Case 2: using bioformats
        String filePath =
        imgPlus.getOriginalFileInfo().directory + imgPlus.getOriginalFileInfo().fileName;

        IFormatReader imgReader = new ImageReader();

        imgReader.setMetadataStore(MetadataTools.createOMEXMLMetadata());

        try
        {
          imgReader.setId(filePath);
        } catch (FormatException e)
        {
          e.printStackTrace();
        } catch (IOException e)
        {
          e.printStackTrace();
        }

        BufferedImageReader buffImgReader = new BufferedImageReader(imgReader);

        try
        {
           BufferedImage buffImg = buffImgReader.openImage(64);

          IJ.log("Case 2 = " + buffImg.getRaster().getSample(128, 128, 0));
          IJ.log("Case 2 = " + buffImg.getRaster().getSample(129, 128, 0));
          IJ.log("Case 2 = " + buffImg.getRaster().getSample(129, 129, 0));
          IJ.log("Case 2 = " + buffImg.getRaster().getSample(128, 129, 0));


        } catch (FormatException e)
        {
           e.printStackTrace();
        } catch (IOException e)
        {
          e.printStackTrace();
        }

I could not reproduce the issue you are describing with the Dot_Blot example image with my own Minimal, Complete, Verifiable Example.

It is possible that the way you are trying to handle your multi-plane image is not the desired way using Bio-Formats. The developers provide some example code in ImageConverter:L329 that uses an ImageReader in quite a different way that what you are proposing. In any case, take a look at the provided examples for how to use Bio-Formats as a Java library.

Best,
Stefan

1 Like

Hi,

Thanks for keeping track of my issue. Please allow me to describe a little more about the situation.

In the first case, I pressed “File” -> “Open…” in the menu bar to read in the image (I use the medical image in minc format), and then I receive the ImagePlus through the setup() method. I wonder if the above import action is default completed by Bioformats ???

Afterward, I read the pixel by imgProcessor.get(x,y) and find out the result is strange. In this case, I actually do little programming but get the unexpected value.

Btw, I just found a website: The image colors do not match what I see in other programs! ImageJ is wrong!
In my case, the autoscale option is disabled, so it might not be the reason. However, it inspired me if there are other default modifications to the raw data made by Bioformats ?

In case 2, thanks for your reference. I will keep studying different ways of reading the image.

Thanks.

Yes, I would advise not to use BufferedImageReader in general, unless you really need it.

Did you try:

ImagePlus[] imps = BF.openImagePlus("/path/to/my/image");

as described here?

I don’t know details but the format you are talking about is definitely not supported by ImageJ so it will be opened with Bio-Formats.

As far as I know, even the “autoscale” option in Bio-Formats does not alter the raw image data but only changes how the raw data is visualized (i.e. the LUTs).

Which Bio-Formats version are you running? You can check that by opening the updater (Help > Update Fiji) and activating the Advanced Mode. Search for “formats-bsd” and get the version from the filename in the details. I am asking since there were some changes in Bio-Formats 5.1.7 (see Release Notes and the original GitHub issue) to how pixel values are read from MINC files…

I guess you have also compared the pixel values to the official MINC software/library? Are the values you get from that implementation the same as from the MATLAB implementation?

Best,
Stefan

1 Like

Hi,

Sorry for the late reply, I tried to use the BF.openImagePlus() instead by changing my bioformat library. I used bioformat_package.jar and now is

<dependency>
  <groupId>ome</groupId>
  <artifactId>bio-formats_plugins</artifactId>
  <version>${bio-formats.version}</version>
</dependency>
<dependency>
  <groupId>ome</groupId>
  <artifactId>formats-api</artifactId>
  <version>${bio-formats.version}</version>
  <exclusions>
    <exclusion>
      <groupId>xalan</groupId>
      <artifactId>serializer</artifactId>
    </exclusion>
    <exclusion>
      <groupId>xalan</groupId>
      <artifactId>xalan</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>ome</groupId>
  <artifactId>formats-bsd</artifactId>
  <version>${bio-formats.version}</version>
  <exclusions>
    <exclusion>
      <groupId>xalan</groupId>
      <artifactId>serializer</artifactId>
    </exclusion>
    <exclusion>
      <groupId>xalan</groupId>
      <artifactId>xalan</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>ome</groupId>
  <artifactId>formats-common</artifactId>
  <version>${bio-formats.version}</version>
  <exclusions>
    <exclusion>
      <groupId>xalan</groupId>
      <artifactId>serializer</artifactId>
    </exclusion>
    <exclusion>
      <groupId>xalan</groupId>
      <artifactId>xalan</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>ome</groupId>
  <artifactId>formats-gpl</artifactId>
  <version>${bio-formats.version}</version>
</dependency>
<dependency>
  <groupId>ome</groupId>
  <artifactId>ome-xml</artifactId>
  <version>${bio-formats.version}</version>
</dependency>

Since then, not only the BF.openImagePlus() but also the way using BufferedImageReader gave expected result !!! Maybe a single Bioformat_package.jar is not sufficent for MINC format ???

By the way, I recall that I chose BufferedImageReader() instead of BF.openImagePlus() as the way to read the file because I want BufferedImage for further processing. The latter is easier by bufferedImageReader.openImage(index). However, it seems that I have to convert pixel by pixel by using the former. Is that right ?

Thanks~~

Stelfrich, thanks for your information. I changed the bioformat library and it looks fine now @@…

Are you inheriting from pom-scijava (or pom-imagej or pom-fiji) as parent? Or importing one of them in your <dependencyManagement> section? If so, you should be able to make your <dependencies> section much simpler. You can leave off the <version> lines, as well as all the exclusions.

1 Like

Hi Rueden,

Thanks for your suggestion. I removed the labels and it works fine.

1 Like