问题
Trying to process raw DNG pictures in Python with rawpy
ends with strange results.
import rawpy
import imageio
from matplotlib import pyplot as plt
path = '/home/stefan/AIJ/RAW.DNG'
with rawpy.imread(path) as raw:
rgb = raw.postprocess()
plt.imshow(rgb)
plt.show()
The result is an rgb picture array with 8-bit values while my camera generates 14 bit raw pictures.
Visualizing the rgb
array gives an expected result:
From some googleing I understood that it is possible to import the same file but with an output in 16-bit.
I used the following parameters in the postprocess function:
rgb = raw.postprocess(output_bps=16,demosaic_algorithm=None,output_color = rawpy.ColorSpace.Adobe)
Now the rgb
array contains 16 bit values but visualizing results in the following:
Could someone tell me how I could obtain a visualization similar to the first result but handling 16-bit values?
Initially I thought it was related to the fact that my camera is producing 14 bit images rather than 16 bit, but changing the parameter output_bps
into 14 gives even worse visualization results.
Thanks in advance!
On request, I would add here the raw picture from a PENTAX K-5 but it is 18MB big and the forum has a limit of 2MB (may be another way to pass you the file?).
回答1:
I don't think the issue has to do with how you are reading the image, as imshow
does not display 16-bit RGB images. So, if you are interested in visually checking the results of reading in the 16-bit image, I would suggest either inspecting bands individually, with
plt.imshow(rgb[:, :, 0])
and so on for each band; or converting the rgb to 8-bit and displaying that, with
rgb8 = (rgb / 256).astype('uint8')
plt.imshow(rgb8)
来源:https://stackoverflow.com/questions/41453129/dng-raw-pictures-imported-as-16-bit-deep-but-unexpected-plt-show-result