I have been able to calculate the correct red and blue gains with the use of the grey card.
At first, I tried it by accessing the rawpy raw_image array and calculating the average of the different color pixels
But the gains I got weren't working, the image was too green (fluorescent illumination). I don't know if there is an error in my code.
Then I found this post in stack overflow https://stackoverflow.com/questions/731 ... with-rawpy that before calculating the average of each color it processes it with rawpy with 1.0 gains.
And the calculated gains work, both by processing the image with rawpy as the code in the post and also by using rpicam-still. And the grey card is "grey", although the resulting image has different colour tonalities.
Thanks for the help!
At first, I tried it by accessing the rawpy raw_image array and calculating the average of the different color pixels
Code:
raw_image_roi = raw.raw_image[roi[1]:roi[3], roi[0]:roi[2]].flatten() raw_color_roi = raw.raw_colors[roi[1]:roi[3], roi[0]:roi[2]].flatten() # print(raw.color_desc) -> 'RGBG' red_pixels = raw_image_roi[np.where(raw_color_roi == 0)] green_pixels = raw_image_roi[np.where((raw_color_roi == 1) | (raw_color_roi == 3))] blue_pixels = raw_image_roi[np.where(raw_color_roi == 2)] red_average = np.mean(red_pixels) green_average = np.mean(green_pixels) blue_average = np.mean(blue_pixels) red_gain = green_average / red_average blue_gain = green_average / blue_average
Then I found this post in stack overflow https://stackoverflow.com/questions/731 ... with-rawpy that before calculating the average of each color it processes it with rawpy with 1.0 gains.
Code:
opts = rawpy.Params(output_color=rawpy.ColorSpace.raw, four_color_rgb=True, no_auto_bright=True, user_wb=[1.0, 1.0, 1.0, 1.0], gamma=(1, 1), output_bps=8, bright=1) rgb_base = raw.postprocess(opts) rgb_base_roi = rgb_base[roi[1]:roi[3], roi[0]:roi[2]] avgR = np.mean(rgb_base_roi[..., 0]) avgG = np.mean(rgb_base_roi[..., 1]) avgB = np.mean(rgb_base_roi[..., 2]) red_gain = avgG / avgR blue_gain = avgG / avgB
Thanks for the help!
Statistics: Posted by paussus — Fri Nov 22, 2024 1:31 pm