gpt4 book ai didi

opencv - 如何降低图像的光强度

转载 作者:行者123 更新时间:2023-12-02 17:52:19 26 4
gpt4 key购买 nike

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

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

最佳答案

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

#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);
}

关于opencv - 如何降低图像的光强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17802779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com