ImagingDataCommons / highdicom

High-level DICOM abstractions for the Python programming language
https://highdicom.readthedocs.io
MIT License
164 stars 34 forks source link

ImageFileReader does not instantiate image object (sometimes) #241

Closed cheyvaert-medexprim closed 7 months ago

cheyvaert-medexprim commented 1 year ago

Hello,

I run on python shell the example from the documentation:

from pydicom.data import get_testdata_file
from highdicom.io import ImageFileReader

test_filepath = get_testdata_file('eCT_Supplemental.dcm')

with ImageFileReader(test_filepath) as image:
    print(image.metadata.SOPInstanceUID)
    for i in range(image.number_of_frames):
        frame = image.read_frame(i)
        print(frame.shape)

It works well.

BUT:

If I tried to do the same with one of my own files:

number_of_frames returns 1, the other method returns empty values, sometimes with error or warning.

BUT: If called twice the number_of_frames method:

with ImageFileReader(test_filepath) as image: image.number_of_frames # calling number_of_frames twice image.number_of_frames # calling number_of_frames twice print(image.metadata.SOPInstanceUID) for i in range(image.number_of_frames): frame = image.read_frame(i) print(frame.shape)

It's working suddenly well.

The image I tried to open weight 2Go, and the modality is SM.

CPBridge commented 1 year ago

Hi @cheyvaert-medexprim, thanks for using the library and reporting this bug. It will help a lot if you provide an deidentified example dataset that demonstrates the issue. I'm afraid I do not understand what you mean in this sentence:

The image I tried to open weight 2Go

Could you explain? Is this some open data?

cheyvaert-medexprim commented 1 year ago

Hi, I didn't have the permission yet from my colleage to send you the dicom image. I'll warn you when I will have it. (Someone thinks it may be linked to the colorimetry but I didnt understand how...)

CPBridge commented 1 year ago

If you can't provide the files, it would be useful if you could confirm a few details:

I suspect this may be related to #235

CPBridge commented 1 year ago

Could you try the branch on #242 ? (Making sure you have pillow<10.0.0 and >=8.3 installed to avoid #243)

cheyvaert-medexprim commented 1 year ago

After a few local test the bug is coming from #243 (it is set by using pillow 2.9.5) thank you. I had the authorization to send you the image today. Just tell me where I can send it to you.

Also:

what is the SOPClassUID of the file? => 1.2.840.10008.5.1.4.1.1.77.1.6
what is the PhotometricInterpretation? => YBR_FULL_422
what is the TransferSyntaxUID? => 1.2.840.10008.1.2.4.50
what are the values of Rows, Columns and NumberOfFrames? =>  256, 256,  6
CPBridge commented 12 months ago

Sorry I am a little confused by your message. Are you saying that your original bug was due to #243, i.e. the version of pillow? That doesn't seem likely me, and pillow 2.9.5 appears not to exist... Did you rather mean that it was fixed by #242?

You can send the files to cbridge at mgh dot harvard dot edu

CPBridge commented 12 months ago

P.s. if indeed this is fixed by #242, I understand the cause of the problem and there's no need to send the files

CPBridge commented 7 months ago

This issue should be resolved in the latest release 0.22.0