Pil Converting From I;16 To Jpeg Produce White Image
I am having a problem converting an image I;16 to JPEG with PIL. My original image can be found here (as pickle). The original image comes from a DICOM file. Here is the code to tr
Solution 1:
Your values are 16-bit and need to be reduced to 8-bit for display. You can scale them from their current range of 2,712 (i.e. ims.min()
) to 4,328 (i.e. ims.max()
) with the following:
from PIL import Image
import numpy as np
import pickle
# Load image
ims = pickle.load(open("pixel_array.pickle", "rb"))
# Normalise to range 0..255
norm = (ims.astype(np.float)-ims.min())*255.0 / (ims.max()-ims.min())
# Save as 8-bit PNG
Image.fromarray(norm.astype(np.uint8)).save('result.png')
Post a Comment for "Pil Converting From I;16 To Jpeg Produce White Image"