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
ValueError: cannot reshape array of size #2006
Comments
Link to the file doesn't work (file has been deleted). Please post the group 0x0028 elements, the transfer syntax UID and the length of the Pixel Data. |
You can attach datasets if you change the extension to .zip/.txt |
Here are the tags....
This is just a zipped version of the file. The extension was not changed, the file was just compressed. Open the zip file to see it's contents. 1.2.826.0.1.3680043.8.498.84891584019088827677474160028118926790.dcm.zip |
Can you paste the output from
as well please? |
Transfer Syntax UID = 1.2.840.10008.1.2.4.90
|
The High Bit/Bits Stored/Bits Allocated values are non-conformant/incorrect... Hmm, change the Bits Stored and Bits Allocated to 8 instead? |
Actually, that may be an opencv issue. |
Are you using pillow for this?
Nope, see below. |
Thank you for taking the time to assist with this issue. It is greatly appreciated. |
OK, the J2K codestream uses 16-bit precision, so Bits Stored and Bits Allocated are correct and High Bit is wrong. Pillow is returning 2359269 bytes, which is wrong for those dimensions and precision. from pydicom.encaps import generate_frames
from pydicom import dcmread
import PIL
ds = dcmread("2006.dcm")
frame = next(generate_frames(ds.PixelData))
im = PIL.Image.open(frame)
len(im.tobytes()) # 2359296
im.mode # 'RGB' This is because Pillow doesn't support RGB data with more than 8-bit depth. So Pillow downscales the 16-bit data to 8-bit. We can't fix this at our end because the downscaling is lossy. @Neuroforge if you want it to work you need to use GDCM or pylibjpeg. Also, just a note that the dataset is non-conformant in at least two ways:
Welp @mrbean-bremen, yet another subset of Pixel Data we can't use Pillow for. |
As I wrote before - I would plead to remove pillow from the supported plugins, now that we have all the |
Describe the bug
Cannot open images which can be opened by other dicom viewers. Image is 768 x 1024 x 3.
Error: ValueError: cannot reshape array of size 1179648 into shape (768,1024,3).
Note: 2359296 = 2 x 1179648
Expected behavior
The pydicom should be able to open the image
Steps To Reproduce
Download this file - https://file.io/ttsJDtW5Hsou (Anonymised dicom file)
Run it with the code snippet below.
Issue seen on Stackoverflow, but no answer provided.
https://stackoverflow.com/questions/67172228/cannot-read-dicom-image
Your environment
macOS-13.5.1-arm64-arm-64bit
Python 3.11.5 (main, Sep 11 2023, 08:31:25) [Clang 14.0.6 ]
pydicom 2.4.4
pynetdicom 2.0.2
The text was updated successfully, but these errors were encountered: