本文主要是介绍LIME低亮度图像增强,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
LIME低亮度图像增强
main.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include "lime.h"int main()
{cv::Mat img_in = cv::imread("3.png"), img_out;if (img_in.empty()){std::cout << "Error Input!" << std::endl;return -1;}feature::lime* l;l = new feature::lime(img_in);img_out = l->lime_enhance(img_in);cv::imshow("test", img_out);cv::waitKey();return 0;
}``![在这里插入图片描述](https://img-blog.csdnimg.cn/2809aa49d0a2413db92b974659ab6062.png)![在这里插入图片描述](https://img-blog.csdnimg.cn/3f4f458bb0e6425bad8f5ae0cbca84f2.png)```lime.cpp
#include "lime.h"namespace feature
{lime::lime(cv::Mat src){channel = src.channels();}cv::Mat lime::lime_enhance(cv::Mat& src){cv::Mat img_norm;src.convertTo(img_norm, CV_32F, 1 / 255.0, 0);cv::Size sz(img_norm.size());cv::Mat out(sz, CV_32F, cv::Scalar::all(0.0));auto gammT = out.clone();if (channel == 3){Illumination(img_norm, out);Illumination_filter(out, gammT);//limestd::vector<cv::Mat> img_norm_rgb;cv::Mat img_norm_b, img_norm_g, img_norm_r;cv::split(img_norm, img_norm_rgb);img_norm_g = img_norm_rgb.at(0);img_norm_b = img_norm_rgb.at(1);img_norm_r = img_norm_rgb.at(2);cv::Mat one = cv::Mat::ones(sz, CV_32F);float nameta = 0.9;auto g = 1 - ((one - img_norm_g) - (nameta * (one - gammT))) / gammT;auto b = 1 - ((one - img_norm_b) - (nameta * (one - gammT))) / gammT;auto r = 1 - ((one - img_norm_r) - (nameta * (one - gammT))) / gammT;cv::Mat g1, b1, r1;//TODO <=1threshold(g, g1, 0.0, 0.0, 3);threshold(b, b1, 0.0, 0.0, 3);threshold(r, r1, 0.0, 0.0, 3);img_norm_rgb.clear();img_norm_rgb.push_back(g1);img_norm_rgb.push_back(b1);img_norm_rgb.push_back(r1);cv::merge(img_norm_rgb, out_lime);out_lime.convertTo(out_lime, CV_8U, 255);}else if (channel == 1){Illumination_filter(img_norm, gammT);cv::Mat one = cv::Mat::ones(sz, CV_32F);float nameta = 0.9;//std::cout<<img_norm.at<float>(1,1)<<std::endl;auto out = 1 - ((one - img_norm) - (nameta * (one - gammT))) / gammT;threshold(out, out_lime, 0.0, 0.0, 3);out_lime.convertTo(out_lime, CV_8UC1, 255);}else{std::cout << "There is a problem with the channels" << std::endl;exit(-1);}return out_lime.clone();}void lime::Illumination(cv::Mat& src, cv::Mat& out){int row = src.rows, col = src.cols;for (int i = 0; i < row; i++){for (int j = 0; j < col; j++){out.at<float>(i, j) = lime::compare(src.at<cv::Vec3f>(i, j)[0],src.at<cv::Vec3f>(i, j)[1],src.at<cv::Vec3f>(i, j)[2]);}}}void lime::Illumination_filter(cv::Mat& img_in, cv::Mat& img_out){int ksize = 5;//mean filterblur(img_in, img_out, cv::Size(ksize, ksize));//GaussianBlur(img_in,img_mean_filter,Size(ksize,ksize),0,0);//gammaint row = img_out.rows;int col = img_out.cols;float tem;float gamma = 0.8;for (int i = 0; i < row; i++){for (int j = 0; j < col; j++){tem = pow(img_out.at<float>(i, j), gamma);tem = tem <= 0 ? 0.0001 : tem; // double epsolon = 0.0001;tem = tem > 1 ? 1 : tem;img_out.at<float>(i, j) = tem;}}}}
这篇关于LIME低亮度图像增强的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!