Replies: 1 comment
-
You have a couple of issues:
if "PixelData" not in ds:
raise AttributeError("This script only works with Pixel Data")
arr = ds.pixel_array
# Apply rescale and windowing prior to processing
arr = arr.astype("float32")
if ds.PixelRepresentation == 1:
# Sample values are signed, range -2 ** (BitsStored - 1) to 2 ** (BitsStored - 1) - 1
# Convert to unsigned in range 0 to 2 ** BitsStored - 1
arr += 2 ** (ds.BitsStored - 1)
# Sample values are in range 0 to 2 ** BitsStored - 1
# Downsample to range 0 to 255
arr = arr / (2 ** ds.BitsStored - 1) * 255
arr = np.clip(arr, 0, 255, dtype='u1', casting='unsafe') You may also want to perform rescale and windowing operations prior to processing. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear all,
I am trying to convert Dicom files to png format. For this purpose, I extracted the code from this issue issue. I changed the saving using cv2.imwrite. Here is my code:
From the code, I am able to convert the dicom to png format, but the color-code are in a reverse way. I have attached the original which is required and the one which I have obtained from the code run. What needs to be changed in order to make the code as in original image?
Original_image_link: Original_image
Image_from_code: Image_obtained
Any leads will be appreciated.
Regards,
Sunag R A.
Beta Was this translation helpful? Give feedback.
All reactions