Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make demosaicing function return RGB values in [0,1] range? #19

Closed
Jiazheng411 opened this issue Jan 3, 2021 · 3 comments
Closed

Comments

@Jiazheng411
Copy link

Jiazheng411 commented Jan 3, 2021

Hi, @KelSolaar , thanks a lot for the lib.
I noticed that the demosaicing function does not return the output in [0,1] range, how can I make it in [0,1] range?

def demosaicing_CFA_Bayer_bilinear(CFA, pattern='RGGB'):
Notes
    -----
    -   The definition output is not clipped in range [0, 1] : this allows for
        direct HDRI / radiance image generation on *Bayer* CFA data and post
        demosaicing of the high dynamic range data as showcased in this
        `Jupyter Notebook <https://github.com/colour-science/colour-hdri/\
blob/develop/colour_hdri/examples/\
examples_merge_from_raw_files_with_post_demosaicing.ipynb>`__.
@Jiazheng411 Jiazheng411 changed the title How to make demosaicing function return RGB values in [0,1] range. How to make demosaicing function return RGB values in [0,1] range? Jan 3, 2021
@sobotka
Copy link

sobotka commented Jan 3, 2021

You will want to find well saturation maximums and minimum for each photosite plane via numpy.amax and then normalize. (photosite - photosite_min) / (photosite_max - photosite_min) should work to normalize to 1.0, for example.

@Jiazheng411
Copy link
Author

Thanks a lot.
By the way, I found the images showed using colour.plotting.plot_image(colour.cctf_decoding(IMG)) is darker than the original image.
for example, this is the original image,
image

after I read the image using img = colour.read_image(img_path)
this is what colour.plotting.plot_image(colour.cctf_decoding(img)) looks like
image
And I do a mosaicing followed by demosaicing, the image looks much lighter,\

CFA_BGGR = mosaicing_CFA_Bayer(img, 'BGGR')
reinter_CFA_BGGR = demosaicing_CFA_Bayer_bilinear(CFA_BGGR, 'BGGR')
colour.plotting.plot_image(colour.cctf_encoding(reinter_CFA_BGGR))

image
is this expected? Or what can I do to eliminate this effects?

@sobotka
Copy link

sobotka commented Jan 4, 2021

Most sensor data is linearly encoded. That is, it is not encoded for display. The subject of preparing colour data for display is likely a wholly other matter.

The linear data then would require some sort of nonlinear curvature to scale and prepare the data for output.

The most simple transform would be to use the display’s inverse EOTF to encode the sensor-linear values for display linear output. For example, using the sRGB inverse EOTF, or more likely, a generic inversion of a 2.2 power function, would prepare linear encoded colour data for projection out of a commodity sRGB-like display.

What you are likely to discover after that unfolds further down the rabbit hole...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants