-
-
Notifications
You must be signed in to change notification settings - Fork 479
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
Transform uint16 to float32 Dicom #1077
Comments
The following should work (but the file will be non-conformant because it doesn't meet the IOD): from pydicom import dcmread
from pydicom.data import get_testdata_file
from pydicom.uid import ImplicitVRLittleEndian
# Original int16 data
ds = dcmread(get_testdata_file("CT_small.dcm"))
arr = ds.pixel_array
ds.FloatPixelData = arr.astype('float32').tobytes()
# Workaround for issue 1075
ds.file_meta.TransferSyntaxUID = ImplicitVRLittleEndian
ds.is_implicit_VR = True
ds['FloatPixelData'].VR = 'OB'
ds.BitsAllocated = 32
ds.BitsStored = 32
ds.HighBit = ds.BitsStored - 1
del ds.PixelData
ds.save_as('float32.dcm') |
@scaramallion thank you for all, now I have my image, with write values and with a good visualization ! |
Hello @scaramallion , |
The maximum bit depth for image data is indeed 16, meaning grayscale images. The bit depth of RGB images is always 8 bit (with 3 channels). There are other kinds of data (not image data) that use OF (e.g. float data as mentioned in this issue) that will take 32 bit, but these will not be displayable by DICOM image viewers. What kind of image data are you trying to write? |
Hi,
My data are np.float32. So, after reading your post I converted it into
16bit format.
factor = np.max(original_image)/65535
image = uint16(original_image/factor)
In this way, data is compatible with dicom viewers.
Thank you 😊
Merry Christmas
mrbean-bremen <notifications@github.com> escreveu no dia terça, 22/12/2020
à(s) 18:30:
… The maximum bit depth for image data is indeed 16, meaning grayscale
images. The bit depth of RGB images is always 8 bit (with 3 channels).
There are other kinds of data (not image data) that use OF (e.g. float
data) that will take 32 bit, but these will not be displayable by DICOM
image viewers. What kind of image data are you trying to write?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1077 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFSCHA2VCOYE6D2LDJ25OTLSWDQV3ANCNFSM4MKUATWA>
.
|
Hi all,
I want to transform uint16 to float32 Dicom. This test seems simple, but in reality I want to do some calculations on it and after whrite it in float32, to not loose data. I do not arrived to save it, so I decide to have a more simple test, read, transform and save it. I have done a lot of tests, each on two cases :
To visualize the result, first I have used Image J, but float value are very wird. If I put the same array if txt image and read raw data, data are okay. If I save like a tiff, data are okay too. But ImageJ seems do not manage float value for dicom (and @scaramallion confirm it in a post). I decide to try with MicroDicom, but the original image is not right visualy and I cannot see values... And tiff image is wrong (and right with image j) Maybe, it is because of the dicom reader, I do not know ...
Following, you will find the code :
`
first_ds = pydicom.dcmread(os.path.join(firstDicomDir,filename))
first_array = first_ds.pixel_array.astype(np.float32)
`
@scaramallion, I have tried your fixif I take the original dicom and chaging this line ds.FloatPixelData = first_array.flatten().tolist() by ds.FloatPixelData = first_array.tobytes(), I have this error: AttributeError: Unable to convert the pixel data: one of Pixel Data, Float Pixel Data or Double Float Pixel Data must be present in the dataset. For the new dicom, the result is not changing with the last version, visualy, but like I have written, I do not know if it is the external reader.
The text was updated successfully, but these errors were encountered: