Giter Site home page Giter Site logo

Comments (4)

Speierers avatar Speierers commented on August 16, 2024

Hi,

For .png and .jpg, the write_bitmap function will apply a sRGB gamma ramp to the pixel color values. Therefore when loading one of those images as a numpy array, this sRGB gamma ramp will be baked in the image. Using it as a reference, the optimization process will converge to a set of parameters that tries to mimic the effect of this gamma ramp.

A solution would be to output an EXR reference image, which is not gamma corrected:

write_bitmap('out_ref.exr', image_ref, crop_size)

# which we can load back from disk:
my_bmp_ref = Bitmap('out_ref.exr')

# and/or convert it to a numpy array
my_np_ref = np.array(my_bmp_ref)

When working with external data (e.g. photo, reference image generated by a different program), it is important to ensure that the format of the reference data matches the output of the differential rendering process (e.g. same color space).

We could maybe expose another parameter to the write_bitmap function to specify whether to apply the sRGB gamma ramp or not (for png and jpg as well).

from mitsuba2.

LeonidMill avatar LeonidMill commented on August 16, 2024

Hi @Speierers,

thank you for your answer. Unfortunately, I'm not too familiar with color spaces and gamma ramps. But if I understand this correctly and I work with external data (i.e. a photo in .png format) I can use something like histogram matching to get the same color space as from the rendering process? However, I guess that the initial guess as output of the diff. rendering process (at the beginning of the optimization) must be at least similar in terms of light conditions?

Is there a possibility to undo the gamma correction in a .png / .jpg image (if the reference image is not available in .exr format)?

from mitsuba2.

Speierers avatar Speierers commented on August 16, 2024

It would be great to know in what color space your reference image lives in and apply the right conversion. Not sure whether histogram matching will be good enough. This will definitely affect the set of parameters (e.g. color values) resulting from the optimization process.

In Mitsuba 2, it is possible to undo the gamma correction in the following way:

import numpy as np
import mitsuba
mitsuba.set_variant("scalar_rgb")
from mitsuba.core import Bitmap, Struct

# Load a PNG from disk (gamma-corrected)
img_srgb = Bitmap("my_image.png")

# Undo the gamma correction
img_linear = img_srgb .convert(Bitmap.PixelFormat.RGB, Struct.Type.UInt8, srgb_gamma=False) 

# Similarly you can convert from Int8 to Float values
img_float = img_srgb .convert(Bitmap.PixelFormat.RGB, Struct.Type.Float32, srgb_gamma=False) 

# Get the corresponding Numpy array
img_np = np.array(img_float)

from mitsuba2.

LeonidMill avatar LeonidMill commented on August 16, 2024

Thank you for your answer. This is what I was looking for.

from mitsuba2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.