2

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:

enter image description here

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:

enter image description here

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?).

noste99
  • 375
  • 3
  • 14
  • Can you share your raw file? It seems unlikely that a normal camera would output a DNG that did not need demosaicing... or isn't it a normal camera? – Mark Setchell Jan 03 '17 at 22:15
  • why ColorSpace.Adobe if you don't apply demosaicing? – Piglet Jan 03 '17 at 22:19
  • This is what I asked myself spontaneously, does this picture needs demosaicing? But because for output_bps=8 bit the output is ok, I did not consider. – noste99 Jan 03 '17 at 22:38
  • On the strange second picture I see the trees in the right bottom corner, so I am almost there. I still did not understood the mechanism of demosaicing and when you need to do it and when not. – noste99 Jan 03 '17 at 22:43

1 Answers1

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)
jdmcbr
  • 5,964
  • 6
  • 28
  • 38
  • Thanks a lot jdmcbr! I will carefully check your suggested solution. I saw via some searching on the web that PyQtGraph module is able to visualize 16 bit pictures. Does someone have experience with this module? St – noste99 Jan 04 '17 at 17:52
  • Dear JDMCBR, what you suggested works fine. Thanks a lot. I am looking in PyQtGraph and this sounds promising. – noste99 Jan 04 '17 at 21:49
  • Great, glad it helped. My limited experience with `pyqtgraph` didn't encourage me to use it instead of `matplotlib`, but I hope it works well for you. – jdmcbr Jan 04 '17 at 22:30