-
Notifications
You must be signed in to change notification settings - Fork 37
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
It prompts Failed to read frame #18, when using highdicom to read the specified dicom file. #235
Comments
Hi @Marsxpc thanks for reporting this issue. I took a quick look and I while I can read the file ok on my linux machine, there is definitely something strange going on: the colours appear to be incorrect and there is some distortion of the frames. I'm not sure whether this is a problem with the library or whether the file is somehow corrupted. I will have to dig in further later. Can you load the entire file correctly with pydicom (just access the pixel_array)? That would be a useful point of reference to figure out what's going on. Thanks |
Ah sorry, I just noticed your comment about pydicom |
Hi @CPBridge |
Hi @Marsxpc thanks for the further information, it will help me investigate further. I suspect that you are correct that this is related to an incorrect frame offset calculation. My results are similar to yours. I think it is unlikely that this is related to the IconImageSequence, since the pixel data for the icon image is stored at a different nested level of the data and so shouldn't interfere with the "main" pixel data. But I will bear it in mind in case it is relevant. I notice that the image is stored with photometric interpretation I will continue to look into the frame offset problem |
P.s. what is the difference between your code that gets the |
like this way:Read all at once, then extract a certain frame |
Some dicom files that contain tag photometric interpretation 'YBR_FULL_422' have abnormal colors after conversion using this code: |
@CPBridge any progress on the investigation? |
@Marsxpc after a little digging this turns out to be fairly simple, I think. Your image uses YBR_FULL_422 photometric interpretation with native (uncompressed) pixels. This means that the two chrominance channels are subsampled by a factor of two relative to the overall image resolution. This is fairly unsual for native pixels as it is typically used with JPEG compression, in which case the JPEG decoder handles this for us. The bug is due to the fact that highdicom does not correctly account for the subsampling when calculating the number of bytes per pixel used to get the offset of a given frame in the PixelData array. Would you please be able to test the fix on #242 for a few of your images and let us know this solves the issue? |
@CPBridge the offset is correct, the colour of image is wrong. I want to know based on which information to set the colour correctly. Do you know this? |
@Marsxpc yes, as the photometric interpretation is from PIL import Image
import numpy as np
# Assuming fm is a numpy array for a single frame, of shape (rows, columns, 3)
im = Image.fromarray(fm, mode="YCbCr")
rgb = np.array(im.convert(mode="RGB")) Note that I am not 100% sure that the YCbCr mode used by pillow exactly matches the definition of the
I will think about whether highdicom should maybe do this colour conversion for you in |
It's a tricky one and I am not sure what the optimal behavior should be in this case. I think we should differentiate between the photometric interpretation of encapsulated encoding and native encoding. In case of encapsulated encoding, the photometric interpretation refers to the compressed representation and the pixels should be converted to RGB upon decoding in my opinion (see pydicom/pydicom#1570 (comment)). I am not sure what to do in case of native encoding. @dclunie what are your thoughts on this? |
Since this is a matter of API design and consistency, and there is no simple answer, I don't really have anything to add beyond what was already discussed in "pydicom/pydicom#1570". Certainly the user needs a means of having the pixels converted to the form they need for rendering (RGB +/- ICC profile application) but they may also need a means of getting the unconverted pixels as discussed in 1570, so whatever is the "default" it needs to be parameterized to allow the other. |
Asked differently, why are the US data natively encoded in YCbCr color space? Are the data supposed to be processed or displayed in that color space? What does the embedded input ICC profile say? My assumption was that the device-specific color space is per definition an RGB color space. My personal preference for highdicom would be to convert color images into RGB color space. However, it raises questions about the appropriate input and output ICC profiles (we currently default to an output ICC profile that converts to sRGB). |
hello, you can reproduce this issue by using the script below:
(environment: windows system and highdicom 0.21.1)
from highdicom.io import ImageFileReader
from pydicom import dcmread, pixel_data_handlers
import numpy as np
import matplotlib.pyplot as plt
path = r'C:\Users\Desktop\XX000090'
frame_idx = 18
with ImageFileReader(path) as image_obj:
arr = image_obj.read_frame(frame_idx, correct_color=False)
plt.imshow(arr)
plt.show()
error message:
Failed to read frame #18. File "C:\Users\test.py", line 12, in
arr = image_obj.read_frame(frame_idx, correct_color=False)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\highdicom\io.py", line 574, in read_frame
frame_data = self.read_frame_raw(index)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\highdicom\io.py", line 545, in read_frame_raw
raise IOError(f'Failed to read frame #{index}.')
Note: Using pydicom to read this dicom file is OK
The text was updated successfully, but these errors were encountered: