MATLAB image processing _YUV and RGB color space of mutual transfer

Source: Internet
Author: User

RGB color Space

About the RGB color space, I believe that the image processing people are more familiar with, or say the R, G, b three components, each component accounted for 8 bits is a byte, three components Total is 3 bytes, that is, 24bit, three components can be combined with different colors, that is, 2^24 species.

So the number of colors that can be expressed is far beyond what we humans can recognize. Each RGB component is actually expressed as brightness, when the three are the same, degenerate into what we call grayscale, such as three components are 0, at this time is black, three components are 255 (8 bits can represent the maximum), this is white, the following picture can be more image description:



YUV Color Space

YUV Three component y means (brightness), U, V for chroma;

About the explanation of YUV look at the analysis in the following article, I will not repeat:

YUV Format detailed


The code is as follows:

% by scott% rgb2yuv% Y = 0.299R + 0.587G + 0.114B% U = -0.147r-0.289g + 0.436B% V = 0.615r-0.515g-0.100b% YUV2 rgb% R = y + 1.14V% G = y-0.39u-0.58v% B = y + 2.03Uclear ALL;CLC; RGB = Imread (' test.jpg '); Imshow (RGB); RGB = Mat2gray (RGB); R = RGB (:,:, 1); G = RGB (:,:, 2); B = RGB (:,:, 3), x = Size (rgb,1), y = size (rgb,2),% Rgb2yuvy = 0.299*r + 0.587*g + 0.114*b; U = -0.147*r-0.289*g + 0.436*b; V = 0.615*r-0.515*g-0.100*b; YUV = Cat (3, Y, U, V); Imshow (YUV);% YUV2RGBRGB1 = zeros (Size (RGB)); RGB1 (:,:, 1) = Y + 1.14 * V; RGB1 (:,:, 2) = Y-0.39 * U-0.58 * V; RGB1 (:,:, 3) = Y + 2.03 * u;figure; Imshow (RGB1)% after YUV to RGB, the image should same with original image.

The results of the operation are as follows:

RGB Space before conversion


YUV Space after conversion


Revert to RGB


MATLAB image processing _YUV and RGB color space of mutual transfer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.