Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rawpy: How to postprocess raw images WITHOUT adulterating pixel data?

I need to convert raw NEF images into numpy arrays for quantitative analysis. I'm currently using rawpy to do this, but I've failed to find a combination of postprocess parameters that leave the pixel data untouched. (I'll be the first to admit I don't entirely understand how raw files work also...)

Here is what I have right now:

rawArray = raw.postprocess(demosaic_algorithm=rawpy.DemosaicAlgorithm.AHD,
                                   half_size=False,
                                   four_color_rgb=False,use_camera_wb=False,
                                   use_auto_wb=False,user_wb=(1,1,1,1),
                                   output_color=rawpy.ColorSpace.raw,
                                   output_bps=16,user_flip=None,
                                   user_black=None,user_sat=None,
                                   no_auto_bright=False,auto_bright_thr=0.01,
                                   adjust_maximum_thr=0,bright=100.0,
                                   highlight_mode=rawpy.HighlightMode.Ignore,
                                   exp_shift=None,exp_preserve_highlights=0.0,
                                   no_auto_scale=True,gamma=(2.222, 4.5),
                                   chromatic_aberration=None,
                                   bad_pixels_path=None)
like image 819
A. Bernard Avatar asked Mar 23 '18 23:03

A. Bernard


1 Answers

Postprocessing, which means demosaicing here, will always change the original pixel values. Typically what you want is to get a linearly postprocessed image so that roughly the number of photons are in linear relation to the pixel values. You can do that with:

rgb = raw.postprocess(gamma=(1,1), no_auto_bright=True, output_bps=16)

In most cases you will not be able to get a calibrated image out where you can directly infer the number of photons that hit the sensor at each pixel. See also https://www.dpreview.com/forums/post/56232710.

Note that you can also access the raw image data via raw.raw_image (see also Bayer matrix) which is as close to the sensor data as you can get -- no interpolation or camera curves etc are applied here, but I would say scientifically you don't get much more than you would get with a linearly postprocessed image as described above.

like image 83
letmaik Avatar answered Sep 21 '22 23:09

letmaik