正规化和均衡化
作者:
地球OLBug
,
2022-10-14 15:03:35
,
所有人可见
,
阅读 214
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
void hit(Mat image, Mat &img, int minn = 0, int maxx = 255)
{
double minVal, maxVal;
image.copyTo(img);
minMaxLoc(img, &minVal, &maxVal);
int n = img.rows;
int m = img.cols * img.channels();
for (int i = 0; i < n; i++)
{
uchar* data = img.ptr<uchar>(i);
for (int j = 0; j < m; j++) {
data[j] = (maxx - minn) / (maxVal - minVal) * (data[j] - minVal) + minn;
}
}
}
int main(int argc, const char* argv[]) {
Mat img = imread("G:/image/xs.jpg"), img_gray;
cvtColor(img, img, COLOR_BGR2GRAY);
resize(img, img, Size(256,256), INTER_AREA);
Mat normalize_img, equal_img;
hit(img, normalize_img);
equalizeHist(img, equal_img);
imshow("Original image", img);
imshow("normalize_img", normalize_img);
imshow("equal_img", equal_img);
waitKey(0);
return 0;
}