用MATLAB 怎么把YCbCr颜色空间的亮度分离啊?

用MATLAB做人脸检测,是基于颜色的,转化成YCbCr空间后亮度分离不会了,哪位高手做过的,帮下忙。如果方便,把整个流程的程序给下~~麻烦的话,只要亮度分离的程序就OK... 用MATLAB做人脸检测,是基于颜色的,转化成YCbCr空间后亮度分离不会了,哪位高手做过的,帮下忙。
如果方便,把整个流程的程序给下~~麻烦的话,只要亮度分离的程序就OK了
展开
 我来答
百度网友b9df065
2008-11-21 · TA获得超过1293个赞
知道小有建树答主
回答量:641
采纳率:0%
帮助的人:736万
展开全部
/**
*颜色选择器颜色转换算法类
*<p>Copyright: langzisoft 13/10/2004</p>
* 山东大学计算机系
* @author 邵建
* @version 1.0
**/

import java.lang.Math;
import java.awt.*;

public class ColorConverter{

public ColorConverter(){
}

//RGB转换CMYk
public int[] rgb2cmyk(int R,int G,int B){
int cmyk []= new int[4];
cmyk[3]=(int)(Math.min(Math.min(255-R,255-G),255-B)/2.55);//cmykK
int MyR = (int)(R/2.55);
int Div = 100-cmyk[3];
if (Div == 0)Div = 1;
cmyk[0] = ((100-MyR-cmyk[3])/Div)*100;//cmykC
int MyG = (int)(G/2.55);
cmyk[1] = ((100-MyG-cmyk[3])/Div)*100;
int MyB = (int)(B/2.55);
cmyk[2] = ((100-MyB-cmyk[3])/Div)*100;

return cmyk;
}
public Color cmyk2rgb(int C,int M,int Y,int K){
float MyC = C/100;
float MyM = M/100;
float MyY = Y/100;
float MyK = K/100;

int R = (int)((1-(MyC*(1-MyK)+MyK))*255);
int G = (int)((1-(MyM*(1-MyK)+MyK))*255);
int B = (int)((1-(MyY*(1-MyK)+MyK))*255);

if (R<0) R=0;
if (G<0) G=0;
if (B<0) B=0;
if (R>255) R=255;
if (G>255) G=255;
if (B>255) B=255;

Color rgb = new Color(R,G,B);
return rgb;
}

public int[] rgb2yuv(int R,int G,int B){

int yuv[] = new int[3];
yuv[0] =(int)(0.299*R+0.587*G+0.114*B);
yuv[1] = (int)(-0.147*R-0.289*G+0.437*B);
yuv[2] = (int)(0.615*R-0.515*G-0.1*B);
return yuv;
}
public Color yuv2rgb(int y,int u,int v){

int R = (int)(y+1.14*v);
int G = (int)(y-0.394*u-0.581*v);
int B = (int)(y+2.028*u);
if (R<0) R=0;
if (G<0) G=0;
if (B<0) B=0;
if (R>255) R=255;
if (G>255) G=255;
if (B>255) B=255;

Color rgb=new Color(R,G,B);
return rgb;
}
public int[] rgb2yiq(int R,int G,int B){

int yiq[] = new int[3];
yiq[0] = (int)(0.299*R+0.587*G+0.114*B);
yiq[1] = (int)(0.596*R-0.274*G-0.322*B);
yiq[2] = (int)(0.212*R-0.523*G+0.311*B);
return yiq;
}
public Color yiq2rgb(float y,float i,float q){

int R = (int)(y+0.956*i+0.621*q);
int G = (int)(y-0.272*i-0.647*q);
int B = (int)(y-1.105*i+1.702*q);

if (R<0) R=0;
if (G<0) G=0;
if (B<0) B=0;
if (R>255) R=255;
if (G>255) G=255;
if (B>255) B=255;

Color rgb = new Color(R,G,B);
return rgb;
}

//RGB转换YCbCr
public int[] rgb2ycbcr(int R, int G,int B){

int ycbcr[] = new int[3];
ycbcr[0] = (int)(0.299*R+0.587*G+0.114*B);
ycbcr[1] = (int)(-0.1687*R-0.3313*G+0.5*B+128);
if (ycbcr[1] > 255) ycbcr[1] = 255;
ycbcr[2] = (int)(0.5*R-0.4187*G-0.0813*B+128);
if (ycbcr[2] > 255) ycbcr[2] = 255;

return ycbcr;
}
public Color ycbcr2rgb(int Y,int Cb,int Cr){
int MyR = (int)(Y + 1.402 * (Cr -128));
int MyG = (int)(Y - 0.34414 * (Cb - 128) - 0.71414 * (Cr - 128));
int MyB = (int)(Y + 1.772 * (Cb -128));

if (MyR > 255) MyR = 255;
if (MyG > 255) MyG = 255;
if (MyB > 255) MyB = 255;

if (MyR < 0) MyR =0;
if (MyG < 0) MyG =0;
if (MyB < 0) MyB =0;

Color rgb = new Color(MyR,MyG,MyB);
return rgb;
}
}

参考资料: http://hi.baidu.com/arm%5Fdsp/blog/item/00e644347527eb4f241f144d.html

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式