如何从输入图像中提取色调范围?我想从图像中提取低色调和高色调,以便在匹配中使用它。
答案 0 :(得分:1)
您需要将图像转换为HSV颜色空间,然后将其拆分为3个通道组件,然后从色调通道中找到最小值和最大值:
Mat img = imread("c:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg");
Mat hsvMat;
cvtColor(img, hsvMat, CV_BGR2HSV); // Convert image to HSV colorspace
vector<Mat> hsvChannels;
split(hsvMat, hsvChannels); // Split the HSV image into the 3 channels
Mat hue = hsvChannels[0]; // This is the hue image
// Find minimum and maximum hue
double minHue = -1;
double maxHue = -1;
cv::minMaxLoc(hue, &minHue, &maxHue, nullptr, nullptr);
cout << "Min hue=" << minHue << " Max hue=" << maxHue << endl;