Issue
I have an image which has a max pixel value - 287.4976094062538
and min pixel value - -41.082841881780645
I am trying to bring them in range between 0-255
what I did:-
- I have divided all the pixel values with max pixel value and then multiplied with 255
- this made my highest pixel value to 1 but my min pixel value is still in negative pixel value
-0.14
.
It is a medical image so I want to preserve every pixel intensities so I don't want to clip them between 0-255
but how can I bring them in that range without clipping(which damage the image structure).
loading them with library like matplotlib
or PIL
automatically clipping the pixel values.
Solution
You are normalizing the positive range of your image only, ignoring the negative values.
You want to apply the following equation to your values:
mx = np.amax(img)
mn = np.amin(img)
img = (img - mn) / (mx - mn) * 255
We're first subtracting the minimum value, so that the minimum value in the image becomes 0. Next we divide to set the maximum value to 1.
mx-mn
is the full range of your data, and therefore the maximum value in the data after setting the minimum to 0.
Answered By - Cris Luengo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.