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

dcm2jpg OutOfMemory error #1259

Open
navrkalpavel opened this issue Nov 3, 2022 · 1 comment
Open

dcm2jpg OutOfMemory error #1259

navrkalpavel opened this issue Nov 3, 2022 · 1 comment

Comments

@navrkalpavel
Copy link

Describe the bug
I have dicom PET image test.zip. Transcoding image to the jpeg by dcm2jpg hangs on OutOfMemory error:

Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        at org.dcm4che3.image.ByteLookupTable.<init>(ByteLookupTable.java:13)
        at org.dcm4che3.image.LookupTableFactory.combineModalityVOILUT(LookupTableFactory.java:278)
        at org.dcm4che3.image.LookupTableFactory.createLUT(LookupTableFactory.java:236)
        at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.applyLUTs(DicomImageReader.java:703)
        at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.applyGrayscaleTransformations(DicomImageReader.java:485)
        at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.read(DicomImageReader.java:468)
        at org.dcm4che3.tool.dcm2jpg.Dcm2Jpg.readImageFromDicomInputStream(Dcm2Jpg.java:438)
        at org.dcm4che3.tool.dcm2jpg.Dcm2Jpg$$Lambda$49/0x000000080015ee78.apply(Unknown Source)
        at org.dcm4che3.tool.dcm2jpg.Dcm2Jpg.convert(Dcm2Jpg.java:425)
        at org.dcm4che3.tool.dcm2jpg.Dcm2Jpg.mconvert(Dcm2Jpg.java:412)
        at org.dcm4che3.tool.dcm2jpg.Dcm2Jpg.main(Dcm2Jpg.java:381)

Thera are no LUT data in the image. Why is dcm4che trying to create lookup table for this image?

Desktop (please complete the following information):

  • OS: Linux
  • Version dcm4che 5.25.2
  • OpenJDK 17
@navrkalpavel navrkalpavel changed the title jpg2dcm OutOfMemory error dcm2jpg OutOfMemory error Nov 3, 2022
@nroduit
Copy link
Member

nroduit commented Dec 30, 2022

The values of WindowWidth and WindowCenter are not consistent with the values of RescaleSlope.

(0028,1050)	DS	WindowCenter		1
(0028,1051)	DS	WindowWidth		1
(0028,1052)	DS	RescaleIntercept	0
(0028,1053)	DS	RescaleSlope		3.51677E-10
(0028,1054)	LO	RescaleType		BQML

The size of LUT divides the WindowCenter by RescaleSlope when WindowCenter is different of 0 (exist).

Unfortunately, it seems not possible to pass WindowCenter to 0 in the parameters of the command (always converted to 1).

So a fix could be to add a new condition, see https://github.com/dcm4che/dcm4che/blob/master/dcm4che-image/src/main/java/org/dcm4che3/image/LookupTableFactory.java#L269-L275

            if (w != 0 && w/m < inBits.maxValue() * 2) {
                size = Math.max(2,Math.abs(Math.round(w/m)));
                offset = Math.round((c-b)/m) - size/2;
            } else {
                offset = inBits.minValue();
                size = inBits.maxValue() - inBits.minValue() + 1;
            }``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants