灰度转换(2):RGB转YCbCr转Gray

  YCbCr

一、YCbCr介绍

二、MATLAB实现

简单

 1 clc;
 2 clear all;
 3 RGB = imread('flower.bmp'); %读取图像
 4 
 5 R = RGB(:,:,1);             %R分量
 6 G = RGB(:,:,2);             %G分量
 7 B = RGB(:,:,3);             %B分量
 8 
 9 [ROW,COL,N] = size(RGB);    %获得图像尺寸[高度,长度,维度]
10 for i = 1:ROW 
11     for j = 1:COL
12         Y(i,j)  =  0.299*R(i,j) + 0.587*G(i,j) + 0.114*B(i,j);
13         Cb(i,j) = -0.172*R(i,j) - 0.339*G(i,j) + 0.511*B(i,j) + 128;
14         Cr(i,j) =  0.511*R(i,j) - 0.428*G(i,j) - 0.083*B(i,j) + 128;
15     end
16 end 
17 
18 subplot(2,2,1);imshow(R);title('R分量灰度图');
19 subplot(2,2,2);imshow(G);title('G分量灰度图');
20 subplot(2,2,3);imshow(B);title('B分量灰度图');
21 subplot(2,2,4);imshow(Y);title('Y分量灰度图');

效果如下:

三、FPGA实现

1、公式改写

2、流水线思想

3、Y分量赋值

四、上板验证

如图:

五、后记

  后续用Y分量进行图像处理即可

猜你喜欢

转载自www.cnblogs.com/xianyufpga/p/12408988.html