删除颜色'阴影' /阴影

时间:2016-09-02 11:37:52

标签: c++ opencv

可以使用哪些OpenCV函数来忽略/滤除颜色(阴影,反射等)的颜色变化' /阴影?

不能从HSV图像中删除“值/强度”通道会创建颜色块并减少/消除由于光线引起的颜色变化/白色阴影吗?

如果您查看下图,*墙壁会涂上一层坚固的奶油色/白色。但它的颜色因阴影和光反射而变化很多。 *参考储物柜上方的白色墙壁。

enter image description here

我认为如果我将图像转换为HSV然后移除值/强度通道,我可以过滤掉那些墙壁反射和阴影,颜色变化 - 即光线。然后我只是减少图像颜色,我应该有一个大的颜色块为墙(在储物柜上方)?也就是说,看到墙上的真实形状/颜色作为一个纯色块。

但是从我上面的图片可以看出,在移除V通道和减少色彩后,墙壁不是一种坚固/一致的颜色。

void removeIntensity()
{
    Mat hsv, hs, reducedHs;
    Mat image = imread("../../Book_Tutorials/images/11.jpg");

    if (image.cols > 300) {
        float scale = 300.0 / (float)image.rows;
        resize(image, image, { int(scale * image.cols), 300 });
    }

    cvtColor(image, hsv, CV_BGR2HSV);

    std::vector<Mat> hsvChannels;
    split(hsv, hsvChannels);

    // Set value/intensity to constant value: can I remove those channels completely?
    hsvChannels[2] = 0;

    merge(hsvChannels, hs);

    reduce(hs, reducedHs, 6);

    imshow("image", image);
    imshow("hsv", hsv);
    imshow("hs", hs);
    imshow("reducedHs", reducedHs);
}

void reduce(const Mat& hsv, Mat& reduced, int nColours)
{
    int n = hsv.rows * hsv.cols;
    std::vector<int> labels;
    Mat centres;
    Mat collapsedImage = hsv.reshape(1, n);
    collapsedImage.convertTo(collapsedImage, CV_32F);

    kmeans(collapsedImage, nColours, labels, TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 10, 1.0),
        3, KMEANS_PP_CENTERS, centres);

    for (int i = 0; i < n; i++) {

        collapsedImage.at<float>(i, 0) = centres.at<float>(labels[i], 0);
        collapsedImage.at<float>(i, 1) = centres.at<float>(labels[i], 1);
        collapsedImage.at<float>(i, 2) = centres.at<float>(labels[i], 2);
    }

    reduced = collapsedImage.reshape(3, hsv.rows);
    reduced.convertTo(reduced, CV_8U);
}

0 个答案:

没有答案