letmaik / rawpy

📷 RAW image processing for Python, a wrapper for libraw
https://pypi.python.org/pypi/rawpy
MIT License
587 stars 67 forks source link

new API to get wb factors from gray box #221

Closed eroux closed 3 months ago

eroux commented 6 months ago

My use case is the following: I have a series of raw files (images of manuscripts) where the first image has a color card but not the following ones. I assume that the camera and settings are the same on all image and that the white balance factors for the first image should be applied to all other images.

dcraw has a way to calculate the white balance based on pixel coordinates (through -A in the command line). I suspect this is also something that libraw has.

My request is that there could be a new function like get_wb(x, y, w, h) that returns the list of 4 wb factors to use to get a white balance that would give a neutral color for the medial pixel in the area given in argument. I could then use that as the user_wb argument of postprocess on all the images.

I tried to get that through some linear interpolation after the postprocessing but unfortunately the result is pretty different (I'm not sure why yet). Being able to extract the wb factors would be the best way for me.

letmaik commented 3 months ago

You can use the technique from here: https://github.com/letmaik/rawpy-notebooks/blob/master/colour-negative/colour-negative.ipynb

eroux commented 3 months ago

thanks! I actually implemented my own thing, admittedly not as clean but I just put it here for reference:

https://github.com/buda-base/scam/blob/c305c5f35ab0610be48ba7ddbedcc4fdb526bf60/raw_utils.py#L100