ome / bioformats

Bio-Formats is a Java library for reading and writing data in life sciences image file formats. It is developed by the Open Microscopy Environment. Bio-Formats is released under the GNU General Public License (GPL); commercial licenses are available from Glencoe Software.
https://www.openmicroscopy.org/bio-formats
GNU General Public License v2.0
380 stars 241 forks source link

DICOM: wrong inversion for 16bit MONOCHROME1 images when WindowCenter is not set but RescaleIntercept is #3619

Open ballaminut opened 4 years ago

ballaminut commented 4 years ago

If a DICOM image has:

IMHO this is due to the fall through (line 586) break; case PHOTOMETRIC_INTERPRETATION: case PIXEL_SPACING: case SLICE_SPACING: case RESCALE_INTERCEPT: case WINDOW_CENTER: [...] break; case RESCALE_SLOPE: addInfo(tag, in.readString(elementLength)); break;

causing the RescaleIntercept to be assigned to centerPixelValue; probably the intended fall through was: break; case WINDOW_CENTER: String winCenter = in.readString(elementLength); if (winCenter.trim().length() == 0) centerPixelValue = -1; else { try { centerPixelValue = new Double(winCenter).intValue(); } catch (NumberFormatException e) { centerPixelValue = -1; } } addInfo(tag, winCenter); break; case PHOTOMETRIC_INTERPRETATION: case PIXEL_SPACING: case SLICE_SPACING: case RESCALE_INTERCEPT: case RESCALE_SLOPE: addInfo(tag, in.readString(elementLength)); break;

(with -1 initial value for centerPixelValue and maxPixelRange)

ballaminut commented 4 years ago

This is a file to test the behavior

000_2560x3328x1_16bit_1.2.840.10008.1.2.dcm.zip

melissalinkert commented 2 years ago

Confirmed that this is still a problem in 6.8.0. The RescaleIntercept is not assigned to centerPixelValue, but the default value of centerPixelValue is 0 and won't be changed when WindowCenter is not present. Similarly, the default value of maxPixelRange is 0 and won't be changed when WindowWidth is not present.

We'll need to improve the inversion logic here as well as the case described in #3620. The relevant DICOM schema section is https://dicom.nema.org/medical/Dicom/current/output/chtml/part03/sect_C.11.2.html#sect_C.11.2.1.2