The YUV420 Planar Image Format.: Color Space Luma Chrominance
The YUV420 Planar Image Format.: Color Space Luma Chrominance
application that takes as input a YUV420 planar image and applies various
filters to it.
1. The YUV420 planar image format.
The YUV color space is one of the standard image formats output by a
wide variety of camera sensors. It encodes a color image or video taking
human perception into account. The YUV model defines a color space in
terms of one luma (Y) and two chrominance (UV) components. There are
several sub-formats of the YUV color space but in this laboratory well
focus on the planar YUV420. Further reading can be found here:
http://en.wikipedia.org/wiki/YUV
A YUV420 image has its pixels coded on 8bits. Every pixel can have
values between 0 and 255, accordingly. This corresponds to a grayscale
representation ranging from black (0) to white (255). This applies for both
luma and chromas. In the 420 format, one of each chroma pixels
correspond to one 4 pixel block in the luma field. This means that for a
HEIGHT x WIDTH dimensioned image, the luma plane will have HEIGHT x
WIDTH pixels and each of the chromas will have (HEIGHT x WIDTH)/4
pixels. The graphical representation for this is as follows:
Figure 1. YUV420 planar format
(http://en.wikipedia.org/wiki/File:Yuv420.svg)
2. Filters.
Image processing filters are kernels that are applied on each pixel of an
input image in order to get a desired effect on the output. Thinking that
an image in memory is represented by a WIDTH x HEIGHT matrix, for
example, a 3x3 kernel applied on one random pixel, takes into account
the value for that particular pixel and the values of the adjacent pixels to
the one in question. Applying the kernel to all pixels in the image, we can
obtain a certain effect.
2.1
The first filter that well talk about is the Gaussian filter. This uses
the Gaussian kernel that replaces every pixel in the input image with a
weighted median of itself and its neighbors. Various implementations
of this filter exist, according to the desired strength of the effect. The
Gaussian filter is used to create a blurred image, because every output
pixel is based on the values of its neighbors. Typically, we can have
3x3, 5x5, 7x7 and so on Gaussian kernels, the bigger the kernel, the
more accentuated the blur effect. The weights of the kernel are again,
subject to discussion but the overall thing to take into account is that
they decrees radially, the biggest weight being, of course, the center
pixel that we take into account.
Lets take for example, the simplest kernel:
2
16
(in_pix[x-1,y-1]*2
in_pix[x-1,y]*8
in_pix[x,y-1]*8
1]*8 +
+ in_pix[x,y]*16 + in_pix[x,y-
in_pix[x+1,y-1]*2
in_pix[x+1,y-1] *2) / 56
in_pix[x+1,y]*8
The operator consists of two 3x3 kernels that are applied to each
pixel. Well define them as follows:
-1
0
-2 -1
Sx =
0
0
-1
-2
-1
and
Sy = *A,
where Sx and
Sy are two images which at each
point contain the horizontal and vertical derivative approximations and
A is the original 3x3 block of the image, centered in the pixel in
question.
This can be interpreted as follows:
Sx[x,y] = (in_pix[x-1,y-1]*(-1)
in_pix[x-1,y-1]*(-1) +
in_pix[x,y-1]*0
in_pix[x,y-1]*0
in_pix[x-1,y]*(-2)
+ in_pix[x,y]*0
+ in_pix[x+1,y]*2
in_pix[x+1,y-1]*1
in_pix[x+1,y-1] *1),
and accordingly for Sy[x,y].