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

Finding ways to modify tags in order to avoid error #599

Closed
shikunyu8 opened this issue Mar 19, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@shikunyu8
Copy link

commented Mar 19, 2018

Description

I am trying to get pixel_data from some dicom images but get an error AttributeError: Amount of pixel data 20145932 does not match the expected data 20145931.

I'm using cbis-ddsm( Digital Database for Screening Mammography ) for research, and I guess this error is due to a conflict in the header file of dicom images in this database.

(0028, 0010) Rows US: 5941
(0028, 0011) Columns US: 3391
(0028, 0100) Bits Allocated US: 8
(0028, 0101) Bits Stored US: 8
(0028, 0102) High Bit US: 7
(0028, 0103) Pixel Representation US: 0
(0028, 0106) Smallest Image Pixel Value US: 0
(0028, 0107) Largest Image Pixel Value US: 255
(7fe0, 0010) Pixel Data OB or OW: Array of 20145932 bytes

As you can see in these tags: 5941*3391 = 20145931 which is not equal to (7fe0, 0010).

I can open these images via ImageJ, therefore the pixel data must be intact. Anyone can help me change (7fe0, 0010) Pixel Data?

Other solutions are greatly appreciated. Thank you.

Steps/Code to Reproduce

RefDs = pydicom.read_file('F:\data_tmp\masks\P_00019_RIGHT_CC_1_MASK.dcm')
RefDs.pixel_array

Expected Results

pixel_value as numpy array

Actual Results

Versions

Windows-8.1-6.3.9600-SP0
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
numpy 1.14.1
pydicom 1.0.2

@mrbean-bremen mrbean-bremen added the bug label Mar 19, 2018

@mrbean-bremen

This comment has been minimized.

Copy link
Member

commented Mar 19, 2018

This looks like a bug in the numpy handler (also in the GDCM handler) - the padding for non-even pixel count is not considered.

rhaxton added a commit to rhaxton/pydicom that referenced this issue Mar 19, 2018

rhaxton added a commit to rhaxton/pydicom that referenced this issue Mar 19, 2018

rhaxton added a commit to rhaxton/pydicom that referenced this issue Mar 19, 2018

@rhaxton

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2018

I think the GDCM handler is OK as it trims the padding around line 156 before checking... I think I must have just copied the length checking code from GDCM to numpy when we refactored the data handlers out. There must have been some reason, but I can't find it in the history. I am not going to take it out just in case. I will add a fix for padding to the numpy handler.

@mrbean-bremen

This comment has been minimized.

Copy link
Member

commented Mar 19, 2018

Ok, I just was going to do the same :) Do you have any test data?

@rhaxton

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2018

I just added two resized versions of the SC_rgb.dcm file (resized to 3 x 3 x 3). One is little endian explicit and the other is jpeg lossy. The checkins are currently running on Travis.

@mrbean-bremen

This comment has been minimized.

Copy link
Member

commented Mar 19, 2018

Ah, I also resampled SC_rgb.dcm - so this seems to be obvious one :)

@rhaxton

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2018

I just found the commit where I broke it:

88c70bb

There is a somewhat valid reason for it. The change is meant to catch the somewhat common case of a file being truncated during transfer/upload/etc... and to produce a clearer error message.

@mrbean-bremen

This comment has been minimized.

Copy link
Member

commented Mar 19, 2018

Ah yes. That's completely sensible code, you just forgot about the padding... been there, done that.

rhaxton added a commit to rhaxton/pydicom that referenced this issue Mar 19, 2018

rhaxton added a commit to rhaxton/pydicom that referenced this issue Mar 19, 2018

rhaxton added a commit to rhaxton/pydicom that referenced this issue Mar 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.