Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NDPIReader & makeRGBImage last scanlines wrong #3059

Closed
mstritt opened this issue Feb 1, 2018 · 5 comments · Fixed by #3526
Closed

NDPIReader & makeRGBImage last scanlines wrong #3059

mstritt opened this issue Feb 1, 2018 · 5 comments · Fixed by #3526
Milestone

Comments

@mstritt
Copy link
Contributor

mstritt commented Feb 1, 2018

When using NDPIReader and converting the data to an image using a BufferdImageReader - or makeRGBImage directly - on some images (probably depending on the height) the last few pixel rows (always 8?) have value 128 instead of the correct pixel value.

The problem can be reproduced on the example image
http://downloads.openmicroscopy.org/images/Hamamatsu-NDPI/manuel/test3-FITC%202%20(485).ndpi

Code:

import loci.formats.FormatReader;
import loci.formats.gui.AWTImageTools;
import loci.formats.in.NDPIReader;
import java.awt.image.BufferedImage;

public class TestNDPIReader {
    public static void main(String[] args) {
        // image from http://downloads.openmicroscopy.org/images/Hamamatsu-NDPI/manuel/test3-FITC%202%20(485).ndpi
        String filename = "test3-FITC 2 (485).ndpi";
        try (FormatReader r = new NDPIReader()) {
            r.setId(filename);
            byte[] bytes = r.openBytes(0);
            int last = bytes[bytes.length-1] & 0xf;   // here the last byte (blue value) is 0, which is correct
            System.out.println(last);    // 0
            // openImage results in value 128 - which is wrong. Trace down to makeRGBImage...
           // BufferedImage bi = AWTImageTools.openImage(bytes,r,r.getSizeX(),r.getSizeY());
           // BufferedImage bi = AWTImageTools.makeImage(bytes, r.getSizeX(), r.getSizeY(), 3, true, 1, false, true, false);
            BufferedImage bi = AWTImageTools.makeRGBImage(bytes, 3, r.getSizeX(), r.getSizeY(), true);
            int lastBi = bi.getRaster().getSample(bi.getWidth()-1,bi.getHeight()-1,0);
            System.out.println(lastBi);  // 128 but should be 0
            // this problem holds for the last 8 scanline pixels (samples width*(height-1..8)*3), before it's correct
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Maybe this is related to #875 and/or #836

Result of the image using a BufferedImageReader (you can see the last part (8 lines) is gray)
testndpi
Zoomin:
testndpi-zoom

@dgault
Copy link
Member

dgault commented Mar 5, 2018

Hi @mstritt, thank you for reporting this issue. I was able to reproduce the behaviour using the first series of the sample file at http://downloads.openmicroscopy.org/images/Hamamatsu-NDPI/manuel/test3-FITC%202%20(485).ndpi as you suggested. From my initial investigation the problem appears to lie within the NDPIReader itself rather than the AWTImageTools functions. This will require further investigation on our side before a fix can be put in place.

@melissalinkert
Copy link
Member

Confirmed that this is still a problem with #3505 included.

melissalinkert added a commit to melissalinkert/bioformats that referenced this issue Mar 12, 2020
…le's stream

Fixes ome#3059

Without this fix, the bytes between the last restart marker and the end of the original JPEG
stream were ignored.
@jfkotw
Copy link

jfkotw commented Apr 9, 2020

I just tested the fix while preparing the latest release of Orbit Image Analysis which uses Bioformats 6.4.0, and it appears that the issue is still present. I verified this by running the same code that @mstritt submitted at the top of this bug report.

jfkotw pushed a commit to jfkotw/LargeNDPIBug that referenced this issue Apr 9, 2020
@jfkotw
Copy link

jfkotw commented Apr 9, 2020

FYI: I pushed the code including the gradle configuration to a repo here: https://github.com/jfkotw/LargeNDPIBug/blob/master/src/main/java/Issue3059.java

@melissalinkert
Copy link
Member

6.4.0 does not contain the fix for this issue, so it is completely expected that you will still see the problem when using 6.4.0.

@sbesson sbesson added this to the 6.5.0 milestone May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants