这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 嵌入式开发» FPGA» DSP图像YCrCb转换成RGB

共6条 1/1 1 跳转至

DSP图像YCrCb转换成RGB

菜鸟
2014-07-13 15:55:10 打赏
最近在做DSP图像处理,需要将采集到的图像从YCrCb转换成RGB格式后,进行图像处理,再将RGB图像转换成YCrCb进行显示,下面是我的图像处理的程序,不知道为什么显示出来的结果总是一片黑,求高手指点。
void videoReverse()
{
int i,j,temp;
int r,g,b,y,cr,cb,pr,pg,pb;
Uint8 *Y,*Cr,*Cb;
for(i=intALines;i{
for(j=intAPixels;j{
Y=(Uint8 *)(tempYbuffer + i*numPixels + j);
Cr=(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j);
Cb=(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j);
y=(*Y);cr=(*Cr);cb=(*Cb);
y-=16;cr-=128;cb-=128;
r=1.164*y+1.596*cr;
g=1.164*y-0.813*cr-0.392*cb;
b=1.164*y+2.017*cb;
if ( r>255 ) r=255;
else if ( r<0 ) r=0;
if ( g>255 ) g=255;
else if ( g<0 ) g=0;
if ( b>255 ) b=255;
else if ( b<0 ) b=0;


temp=2*g-r-b;
if ( temp>255 ) temp=255;
else if ( temp<0 ) temp=0;
r=abs(temp);g=abs(temp);b=abs(temp);
pr=abs(0.257*r+0.504*g+0.098*b+16);
*(Uint8 *)(tempYbuffer + i*numPixels + j)=pr;
pb=abs(-0.148*r-0.291*g+0.439*b+128);
*(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j)=pb;
pr=abs(0.439*r-0.368*g-0.071*b+128);
*(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j)=pg;
Y++;Cr++;Cb++;
}
}
for(i=numLines/2+intALines;i{
for(j=intAPixels;j{
Y=(Uint8 *)(tempYbuffer + i*numPixels + j);
Cr=(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j);
Cb=(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j);
y=(*Y);cr=(*Cr);cb=(*Cb);
y-=16;cr-=128;cb-=128;
r=1.164*y+1.596*cr;
g=1.164*y-0.813*cr-0.392*cb;
b=1.164*y+2.017*cb;
if ( r>255 ) r=255;
else if ( r<0 ) r=0;
if ( g>255 ) g=255;
else if ( g<0 ) g=0;
if ( b>255 ) b=255;
else if ( b<0 ) b=0;
temp=2*g-r-b;
if ( temp>255 ) temp=255;
else if ( temp<0 ) temp=0;
r=abs(temp);g=abs(temp);b=abs(temp);
pr=abs(0.257*r+0.504*g+0.098*b+16);
*(Uint8 *)(tempYbuffer + i*numPixels + j)=pr;
pb=abs(-0.148*r-0.291*g+0.439*b+128);
*(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j)=pb;
pr=abs(0.439*r-0.368*g-0.071*b+128);
*(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j)=pg;
Y++;Cr++;Cb++;
}
}
}



关键词: YCrCb 图像 RGB

工程师
2014-07-13 21:21:31 打赏
2楼
我给你呼叫会的人

菜鸟
2014-07-14 11:38:30 打赏
3楼
谢谢了

高工
2014-07-14 13:04:03 打赏
4楼
图像处理完全不懂,帮顶吧,晚上回去看看网上有没有类似的代码

菜鸟
2014-07-14 16:38:29 打赏
5楼
灰常感谢

专家
2014-07-30 21:28:38 打赏
6楼
似乎你的代码要优化哦!!执行起来跑的时间很费时!

共6条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]