RGBtoYUV - Maple Help

ImageTools

 RGBtoYUV
 convert an RGB color image to a YUV color image

 Calling Sequence RGBtoYUV( img, opts )

Parameters

 img - ColorImage or ColorAImage; input image opts - (optional) equation(s) of the form option = value; specify options for the RGBtoYUV command

Options

 • inplace = truefalse
 Specifies whether the operation is performed in-place. This can be used to avoid allocating memory. The default is false.
 • output = Image
 Specifies a data structure into which the output is written. This can be used to avoid allocating memory. The size and number of layers must match that of the input. The dimensions of the output image are adjusted so that the row and column indices match the input. The default is NULL.

Description

 • The RGBtoYUV command converts a color image with an RGB color representation to a YUV color representation. The following linear transformation is applied at each position in the image to the three color layers:

$\mathrm{Matrix}\left(\left[\left[y\right],\left[u\right],\left[v\right]\right]\right)=\mathrm{Matrix}\left(\left[\left[0.299,0.587,0.114\right],\left[-0.147,-0.289,0.436\right],\left[0.615,-0.515,-0.100\right]\right]\right)\mathrm{Matrix}\left(\left[\left[r\right],\left[g\right],\left[b\right]\right]\right)$

 • The alpha channel (layer 4), if present, is not affected.
 • The img parameter is the input image and must be of type ColorImage or ColorAImage.

Examples

 > $\mathrm{with}\left(\mathrm{ImageTools}\right):$

Create three monochromatic images representing the RGB layers and then combine them into a single color image.

 > $\mathrm{img_r}≔\mathrm{Create}\left(100,200,\left(r,c\right)↦0.25\cdot \left(1+\mathrm{sin}\left(\left(0.005+0.003\cdot c\right)\cdot c\right)\right)\cdot \left(1+\mathrm{sin}\left(0.15\cdot r\right)\right)\right):$
 > $\mathrm{img_g}≔\mathrm{Create}\left(100,200,\left(r,c\right)↦0.5\cdot \left(1+\mathrm{exp}\left(-\frac{r}{50.}\right)\cdot \mathrm{sin}\left(\frac{c}{20.}\right)\right)\right):$
 > $\mathrm{img_b}≔\mathrm{Create}\left(100,200,\left(r,c\right)↦\frac{r}{100.}\right):$
 > $\mathrm{img_rgb}≔\mathrm{CombineLayers}\left(\mathrm{img_r},\mathrm{img_g},\mathrm{img_b}\right):$

Convert the color image to a YUV representation and then extract each layer as a separate monochromatic image.

 > $\mathrm{img_yuv}≔\mathrm{RGBtoYUV}\left(\mathrm{img_rgb}\right):$
 > $\mathrm{img_y}≔\mathrm{FitIntensity}\left(\mathrm{GetLayer}\left(\mathrm{img_yuv},1\right)\right):$
 > $\mathrm{img_u}≔\mathrm{FitIntensity}\left(\mathrm{GetLayer}\left(\mathrm{img_yuv},2\right)\right):$
 > $\mathrm{img_v}≔\mathrm{FitIntensity}\left(\mathrm{GetLayer}\left(\mathrm{img_yuv},3\right)\right):$

Display the original RGB layers, the color image, and the YUV layers.

 > $\mathrm{Embed}\left(\left[\mathrm{img_r},\mathrm{img_g},\mathrm{img_b}\right]\right)$

 > $\mathrm{Embed}\left(\mathrm{img_rgb}\right)$

 > $\mathrm{Embed}\left(\left[\mathrm{img_y},\mathrm{img_u},\mathrm{img_v}\right]\right)$