c++ opencv实现图像对比度增强
生活随笔
收集整理的這篇文章主要介紹了
c++ opencv实现图像对比度增强
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#include<iostream>
#include<opencv2/opencv.hpp>
#include<math.h>using namespace cv;int main()
{Mat example = imread("D:\\VC項(xiàng)目\\img1.jpg");if (!example.data){printf("無法打開圖像!!!");return -1;}imshow("example", example);Mat outexample;// "********方式一(源碼對(duì)圖像進(jìn)行掩膜操作)*********************"example.copyTo(outexample);//把原圖片拷貝給outexampleint example_c = example.channels();//獲取圖片的通道數(shù) int height = example.rows;//得到圖片的高度int width = example.cols;//得到圖片的寬度 int cols = example.cols * example_c;//利用通道數(shù)*圖片的寬度for (int row = 1; row < height - 1; row++){const uchar* previous = example.ptr<uchar>(row - 1); //獲取前一行的指針const uchar* current = example.ptr<uchar>(row);//獲取當(dāng)前行的指針const uchar* next = example.ptr<uchar>(row +1);// 獲取下一行的指針uchar* output = outexample.ptr<uchar>(row);for (int col = example_c; col < example_c * (example.cols - 1); col++){*output = saturate_cast<uchar>(5 * current[col] - previous[col] - next[col] - current[col - example_c] - current[col + example_c]);output++;}} printf("輸入圖片的信息:\n");std::cout << "通道數(shù):"<<example_c<<"\n";std::cout << "圖片的大小:" << width << "*" << height;// "********方式二(直接利用cv種的filter2D對(duì)圖像進(jìn)行掩膜操作)*********************"Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 10, -1, 0, -1, 0);filter2D(example, outexample, example.depth(), kernel);imshow("outexample", outexample);waitKey(0);return 0;
}
總結(jié)
以上是生活随笔為你收集整理的c++ opencv实现图像对比度增强的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 原始传奇手游服务器不显示,原始传奇闪退黑
- 下一篇: s3c2440移植MQTT