#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
//分水岭血管作业1,使用连通域方法
int main()
{
Mat src = imread("E:\\哈工智能\\fenge\\watershedone\\color.jpg");
if (src.empty())
{
printf("could not load image....\n");
return -1;
}
Mat cropImg;
Rect cropRect1280(360, 60, 500, 173);//dawei 1280*960裁剪尺寸
//裁取感兴趣区域
cropImg = src(cropRect1280);
imshow("cropImg", cropImg);
cvtColor(cropImg, cropImg, COLOR_BGR2HSV);
for (int i = 0; i < cropImg.rows; i++)
{
for (int j = 0; j < cropImg.cols; j++)
{
int H = static_cast<int>(cropImg.at<Vec3b>(i, j)[0]);
int S = static_cast<int>(cropImg.at<Vec3b>(i, j)[1]);
int V = static_cast<int>(cropImg.at<Vec3b>(i, j)[2]);
if (((H < 30) || (H > 160 && H < 180)) && (S > 73 && V > 86))
{
continue;
}
else
{
cropImg.at<Vec3b>(i, j)[0] = 0;
cropImg.at<Vec3b>(i, j)[1] = 0;
cropImg.at<Vec3b>(i, j)[2] = 0;
}
}
}
cvtColor(cropImg, cropImg, COLOR_HSV2BGR);
imshow("cropImg", cropImg);
waitKey(0);
return 0;
}
数字图像处理项目:RGB转为HSV
最新推荐文章于 2023-03-23 12:22:12 发布