.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_tiny_image.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_validation_validate_tiny_image.py: Tiny Image Validation ===================== This example shows the ability to render different images of small sizes from 32x32 to 1x1 pixels in both RGB and grayscale formats. 1x1 pixel images might seem strange but can occurs in algorithm development where the applicability of an algorithm is tested against extreme bounds. .. GENERATED FROM PYTHON SOURCE LINES 12-71 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_tiny_image_001.webp :alt: validate tiny image :srcset: /_gallery/validation/images/sphx_glr_validate_tiny_image_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np import imageio.v3 as iio from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas(size=(180 * 5, 40 * 5)) renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() camera = gfx.OrthographicCamera(180, 40) camera.local.y = 16 camera.local.scale_y = -1 camera.local.x = 176 / 2 astronaut = iio.imread("imageio:astronaut.png") # astronaut is a 512x512 image, resize it to 32x32 # anti-aliasing is bad, but it shows funny effects too! astronaut_32x32 = astronaut[::16, ::16] astronaut_32x32_grayscale = np.sum( np.asarray([1.0, 1.0, 1.0]) / 3 * astronaut_32x32, axis=-1, ).astype(np.uint8) position_rgb = 0 position_gray = 176 for i in [ 32, 16, 8, 4, 2, 1, ]: image_rgb = astronaut_32x32[:: 32 // i, :: 32 // i] image_gfx = gfx.Image( gfx.Geometry(grid=gfx.Texture(image_rgb, dim=2)), gfx.ImageBasicMaterial(clim=(0, 255)), ) image_gfx.local.x = position_rgb position_rgb += i + 10 scene.add(image_gfx) image_gray = astronaut_32x32_grayscale[:: 32 // i, :: 32 // i] image_gfx = gfx.Image( gfx.Geometry(grid=gfx.Texture(image_gray, dim=2)), gfx.ImageBasicMaterial(clim=(0, 255)), ) image_gfx.local.x = position_gray - i image_gfx.local.y = 32 - i scene.add(image_gfx) position_gray -= i + 10 canvas.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.205 seconds) .. _sphx_glr_download__gallery_validation_validate_tiny_image.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_tiny_image.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_tiny_image.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_tiny_image.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