Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions examples/image/image_yuv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
YUV Image
=========

Example that shows how to use YUV images. Most videos are stored in this colorspace.
Y stores luma at full resolution, UV stores chroma values.
In yuv420p UV channels are stored at half the resolution of Y. In yuv444p, UV channels are stored
at full resolution.

YUV is also called YCbCr for digital images.

For more info: https://en.wikipedia.org/wiki/Y%E2%80%B2UV

You can see the slight differences between yuv420 and yuv444 if you zoom into parts of the image where colors change
rapidly over space, such as the astronaut's patch.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import numpy as np
from skimage.color import rgb2ycbcr
import imageio.v3 as iio

# convert an rgb image to ycbcr for example purposes
img = iio.imread("imageio:astronaut.png")
img_yuv = rgb2ycbcr(img).astype(np.uint8)

y = img_yuv[..., 0]
u = img_yuv[..., 1]
v = img_yuv[..., 2]

figure = fpl.Figure(
shape=(1, 2), names=["yuv420p", "yuv444p"], controller_ids="sync", size=(700, 400)
)

image1 = figure[0, 0].add_image_yuv(
data=(y, u[::2, ::2], v[::2, ::2]), colorspace="yuv420p"
)

image2 = figure[0, 1].add_image_yuv(data=(y, u, v), colorspace="yuv444p")

cursor = fpl.Cursor()

for subplot in figure:
cursor.add_subplot(subplot)

figure.show()


# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()
1 change: 1 addition & 0 deletions fastplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .utils import loop # noqa
from .utils import (
config,
enums,
enumerate_adapters,
select_adapter,
print_wgpu_report,
Expand Down
3 changes: 2 additions & 1 deletion fastplotlib/graphics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ._base import Graphic
from .line import LineGraphic
from .scatter import ScatterGraphic
from .image import ImageGraphic
from .image import ImageGraphic, ImageYUVGraphic
from .image_volume import ImageVolumeGraphic
from ._vectors import VectorsGraphic
from .mesh import MeshGraphic, SurfaceGraphic, PolygonGraphic
Expand All @@ -14,6 +14,7 @@
"LineGraphic",
"ScatterGraphic",
"ImageGraphic",
"ImageYUVGraphic",
"ImageVolumeGraphic",
"VectorsGraphic",
"MeshGraphic",
Expand Down
4 changes: 4 additions & 0 deletions fastplotlib/graphics/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
)
from ._image import (
TextureArray,
TextureYUV,
TupleYUV,
ImageCmap,
ImageVmin,
ImageVmax,
Expand Down Expand Up @@ -93,6 +95,8 @@
"VertexPointSizes",
"UniformSize",
"TextureArray",
"TextureYUV",
"TupleYUV",
"ImageCmap",
"ImageVmin",
"ImageVmax",
Expand Down
Loading