.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/physical_color.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_feature_demo_physical_color.py: Physical Color ============== Pygfx by default assumes that all colors are in the sRGB colorspace. This example shows how you can also provide colors in physical colorspace (a.k.a. linear-srgb). This example shows 3 images: * A normal image in sRGB. * An image in physical colorspace, shows up too dark. * An image in physical colorspace, rendered correctly. .. GENERATED FROM PYTHON SOURCE LINES 13-67 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_physical_color_001.webp :alt: physical color :srcset: /_gallery/feature_demo/images/sphx_glr_physical_color_001.webp :class: sphx-glr-single-img .. code-block:: Python import imageio.v3 as iio from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import numpy as np canvas = RenderCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() def read_srgb_color_image(): return iio.imread("imageio:astronaut.png").astype(np.float32) / 255 def read_physical_color_image(): # We fake it by reading a simple srgb image and gamma decoding it return read_srgb_color_image() ** 2.2 im1 = read_srgb_color_image() im2 = read_physical_color_image() material = gfx.ImageBasicMaterial(clim=(0, 1)) image1 = gfx.Image( gfx.Geometry(grid=gfx.Texture(im1, dim=2)), material, ) image1.local.x = 0 image2 = gfx.Image( gfx.Geometry(grid=gfx.Texture(im2, dim=2)), material, ) image2.local.x = 550 image3 = gfx.Image( gfx.Geometry(grid=gfx.Texture(im2, dim=2, colorspace="physical")), material, ) image3.local.x = 1100 scene.add(image1, image2, image3) camera = gfx.OrthographicCamera(1650, 550) camera.local.position = (805, 256, 0) camera.local.scale_y = -1 if __name__ == "__main__": canvas.request_draw(lambda: renderer.render(scene, camera)) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.374 seconds) .. _sphx_glr_download__gallery_feature_demo_physical_color.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: physical_color.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: physical_color.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: physical_color.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html