实用计算机视觉 -- 彩色空间应用

在图像处理和计算机视觉中,基于彩色空间有许多的应用,本实验主要涉及基于HLS模型的皮肤检测和红眼检测,测试图片如下:


在OpenCV中,将RGB图像转换到HLS空间的效果如下:


在大量的研究实验工作后,(S>=50)  && (L_S_ratio>0.5) && (L_S_ratio<3.0) && ((H<=14) || (H>=165))的模型较为可靠,下面分别是测试代码和效果:

void skinDetect(Mat &hls_image, Mat &bina_image){
	CV_Assert(hls_image.channels() == 3 && bina_image.type() == CV_8UC1);
	for (int row = 0; row < hls_image.rows; ++row)
		for (int col = 0; col < hls_image.cols; ++col)
		{
			uchar H = hls_image.at<Vec3b>(row, col)[0];
			uchar L = hls_image.at<Vec3b>(row, col)[1];
			uchar S = hls_image.at<Vec3b>(row, col)[2];
			double LS_ratio = ((double)L) / ((double)S);
			bina_image.at<uchar>(row, col) = ((S >= 50) && (LS_ratio>0.5) &&
				(LS_ratio < 3.0) && ((H <= 14) || (H>165)))? 255:0;
		}
	
}

在红眼检测中,(L>=64) && (S>=100) && (L_S_ration>0.5) && (L_S_ratio<1.5) && ((H<=7) || (H>=162))的模型较为可靠。

void redEyeDetect(Mat &hls_image, Mat &bina_image){
	CV_Assert(hls_image.channels() == 3 && bina_image.type() == CV_8UC1);
	for (int row = 0; row < hls_image.rows; ++row)
		for (int col = 0; col < hls_image.cols; ++col)
		{
			uchar H = hls_image.at<Vec3b>(row, col)[0];
			uchar L = hls_image.at<Vec3b>(row, col)[1];
			uchar S = hls_image.at<Vec3b>(row, col)[2];
			double LS_ratio = ((double)L) / ((double)S);
			bina_image.at<uchar>(row, col) = ((L >= 64) && (S>=100) &&
				(LS_ratio >0.5) && (LS_ratio<1.5) && ((H <= 7) || (H>162)))? 255:0;
		}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值