当前位置:网站首页>First knowledge of opencv4.x --- image histogram equalization
First knowledge of opencv4.x --- image histogram equalization
2022-07-25 09:47:00 【F l e】
// Image histogram equalization
#include <stdio.h>
#include <iostream>
#include <string>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
void drawHist(Mat &hist, int hist_w, int hist_h, int type, string name);
int main()
{
/* Histogram equalization can change the original gray concentration into dispersion , This will prevent the image from being too dark or too bright , Make the outline of the image clearer */
Mat img = imread("gearwheel.jpg", IMREAD_GRAYSCALE);
// Statistics 0~255 The number of pixels of each gray value
const int channels[1] = {
0 };
Mat hist;
const int histSize[1] = {
256 };
float a[2] = {
0,255 };
const float * ranges[1] = {
a };
calcHist(&img, 1, channels, Mat(), hist, 1, histSize, ranges);// Got hist It's a single channel ,width=1,height=256 Of Mat Variable
// Normalized histogram comparison
drawHist(hist, 512, 400, NORM_INF, "hist_nor");
Mat img_equ;
equalizeHist(img, img_equ);
calcHist(&img_equ, 1, channels, Mat(), hist, 1, histSize, ranges);// Got hist It's a single channel ,width=1,height=256 Of Mat Variable
drawHist(hist, 512, 400, NORM_INF, "hist_equ_nor");
// Gray image comparison after equalization
imshow("img", img);
imshow("img_equ", img_equ);
waitKey(0);
return 0;
}
// Draw histogram function , Pass in the parameter :hist, Image width , High image , Normalization mode , Window name
void drawHist(Mat &hist, int hist_w, int hist_h,int type, string name)// This function is suitable for NORM_INF Method
{
int width = 2;
Mat histImage = Mat::zeros(hist_h, hist_w, CV_8UC3);
normalize(hist, hist, 1, 0, type, -1, Mat());
for (int i = 1; i <= hist.rows; i++)
{
rectangle(histImage, Point(width*(i - 1), hist_h - 1),
Point(width*i - 1, hist_h - cvRound(hist_h*hist.at<float>(i - 1)) - 1),
Scalar(255, 255, 255), -1);
}
imshow(name, histImage);
}


边栏推荐
- [data mining] Chapter 2 understanding data
- A number converted from a decimal integer to another base
- Flutter rive multi state example
- Customize dialog to realize the pop-up box of privacy clause statement imitating Netease cloud music
- OC -- Foundation -- Collection
- 初识Opencv4.X----图像直方图匹配
- OC -- object replication
- [code source] score split of one question per day
- chmod和chown对挂载的分区的文件失效
- 初识Opencv4.X----均值滤波
猜你喜欢
随机推荐
[code source] daily question tree
OC -- Foundation -- dictionary
matlab如何导入大量数据
chmod和chown对挂载的分区的文件失效
UI - infinite rotation chart and column controller
Learning new technology language process
Swift简单实现待办事项
Flex layout syntax and use cases
First knowledge of opencv4.x --- image convolution
Raspberry sect door ban system based on face recognition
Assignment 7.21 Joseph Ring problem and decimal conversion
[gplt] 2022 popular lover (Floyd)
UI原型资源
Operation 7.19 sequence table
无向连通图邻接矩阵的创建输出广度深度遍历
First knowledge of opencv4.x --- drawing shapes on images
Android 如何使用adb命令查看应用本地数据库
Kotlin协程:协程的基础与使用
初识Opencv4.X----为图像添加椒盐噪声
本地存储待办事项(在待办事项上进行改进)









