How to properly rescale pixel values to be in the range [0, 1]? #1656
Unanswered
CristianoPizzamiglio
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Thanks for this beautiful library!
This question is very similar to the one asked on SO. However, I am struggling to apply the suggested solution.
I have loaded a CT dicom image having 512 rows and 512 columns:
Then, I have created a 2D numpy array, called
mask
, having shape(512, 512)
that consists only of0
s and1
s.I have converted
mask
values to benp.float16
as suggested here and then I have overwrittenPixelData
as explained here:Finally, I have written the modified dicom to file:
However, when I open the newly created file with a DICOM viewer software, instead of having
0
s and1
s as pixel values, I get-1024
s and2048
s.My first solution was to applied the method proposed in the comment by @scaramallion in the SO link provided above:
but now I get
-1024
s and2857
s as pixel values. Maybe I have not properly understood @scaramallion comment and so the formulas are not correct.Lastly, I have modified
RescaleIntercept
andRescaleSlope
and set them to0
and1 / 2048
respectively. Now I am actually getting0
s and1
s in the newly created dicom file. But considering the answer by @scaramallion in the SO link above, I wonder if this is the proper way to normalize the pixel values.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions