1

从 opencv (cat.jpg) 获取示例图像。降低特定区域的亮度。这是图片的链接

http://tinypic.com/view.php?pic=2lnfx46&s=5

4

1 回答 1

1

这是一种可能的解决方案。使用简单的阈值操作检测亮点。然后使用伽马变换使亮点变暗。结果看起来稍微好一些,但不幸的是,如果图像中的像素完全是白色的,那么所有像素信息都会丢失,您将无法恢复这些信息。

#include <opencv2/opencv.hpp>
#include <iostream>
#include <cfloat>

int threshold = 200;
double gammav = 3;

int main(int argc, char** argv )
{
    cv::Mat image,gray_image,bin_image;

    // read image
    cv::imread(argv[1]).convertTo(image,CV_32FC3);

    // find bright spots with thresholding
    cv::cvtColor(image, gray_image, CV_RGB2GRAY);
    cv::threshold( gray_image, bin_image, threshold, 255,0 );

    // blur mask to smooth transitions
    cv::GaussianBlur(bin_image, bin_image, cv::Size(21,21), 5 );

    // create 3 channel mask
    std::vector<cv::Mat> channels;
    channels.push_back(bin_image);
    channels.push_back(bin_image);
    channels.push_back(bin_image);
    cv::Mat bin_image3;
    cv::merge(channels,bin_image3); 

    // create darker version of the image using gamma correction
    cv::Mat dark_image = image.clone();
    for(int y=0; y<dark_image.rows; y++)
       for(int x=0; x<dark_image.cols; x++)
         for(int c=0;c<3;c++)
            dark_image.at<cv::Vec3f>(y,x)[c] = 255.0 * pow(dark_image.at<cv::Vec3f>(y,x)[c]/255.0,gammav);

    // create final image
    cv::Mat res_image = image.mul((255-bin_image3)/255.0) + dark_image.mul((bin_image3)/255.0);


    cv::imshow("orig",image/255);
    cv::imshow("dark",dark_image/255);
    cv::imshow("bin",bin_image/255);
    cv::imshow("res",res_image/255);

    cv::waitKey(0);
}

在此处输入图像描述

于 2013-07-23T12:31:05.027 回答