OpenCV Tutorials —— Histogram Equalization

直方图均衡化 —— 其潜在的数学原理是一个分布(输入的亮度直方图)被映射到另一个分布

其目的是拉伸原始图像直方图,增强其对比度

 

  • To accomplish the equalization effect, the remapping should be the cumulative distribution function (cdf) (more details, refer to Learning OpenCV). For the histogram , its cumulative distribution is:

    累计分布函数作为映射函数,计算的过程中需要归一化直方图

    To use this as a remapping function, we have to normalize such that the maximum value is 255 ( or the maximum value for the intensity of the image ). From the example above, the cumulative function is:

  • Finally, we use a simple remapping procedure to obtain the intensity values of the equalized image:

 

 

Code

 

#include "stdafx.h"

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

/**  @function main */
int main( int argc, char** argv )
{
	Mat src, dst;

	char* source_window = "Source image";
	char* equalized_window = "Equalized Image";

	/// Load image
	src = imread( "test1.jpg", 1 );

	if( !src.data )
	{ cout<<"Usage: ./Histogram_Demo <path_to_image>"<<endl;
	return -1;}

	/// Convert to grayscale
	cvtColor( src, src, CV_BGR2GRAY );

	/// Apply Histogram Equalization
	equalizeHist( src, dst );	// 全封装进去了 ~~

	/// Display results
	namedWindow( source_window, CV_WINDOW_AUTOSIZE );
	namedWindow( equalized_window, CV_WINDOW_AUTOSIZE );

	imshow( source_window, src );
	imshow( equalized_window, dst );

	/// Wait until user exits the program
	waitKey(0);

	return 0;
}

 

直方图均衡化 —— 频谱被展开

对于彩色图像,必须先将每个通道分开,再分别进行处理

适用于直方图分布过于集中(对比不明显的)图像

时间: 2024-10-14 05:31:31

OpenCV Tutorials —— Histogram Equalization的相关文章

OpenCV Tutorials &mdash;&mdash; Histogram Comparison

直方图匹配   OpenCV implements the function compareHist to perform a comparison. 1,Correlation ( CV_COMP_CORREL ) 线性相关,完全匹配的数值为1,完全不匹配是-1 where and is the total number of histogram bins. 2,Chi-Square ( CV_COMP_CHISQR ) 卡方 ~  完全匹配是0,完全不匹配为无穷 3,Intersection

OpenCV Tutorials &mdash;&mdash; Histogram Calculation

Let's identify some parts of the histogram: 1,dims: The number of parameters you want to collect data of. 2,bins: It is the number of subdivisions in each dim. 3,range: The limits for the values to be measured. void calcHist(const Mat* images, int ni

学习opencv tutorials

1.opencv里头动态库和静态库的区别 lib是动态库,staticlib是静态库. 这是opencv tutorials中对动态库和静态库的说明.动态库是在runtime时候才load的库文件.而静态库文件会在你build的时候build-in inside your exe file.优点是可以避免误删,缺点是应用程序变大,加载时间也会变长. 2.  Visual Studio中solution和project的关系 在VS中,一个solution中可以包含多个project. 3.  两

图像处理(四)——直方图均衡(Histogram Equalization)

直方图均衡(Histogram Equalization) 1. 总述 对于一张灰度图来说,每个像素点的取值为0~255,0表示黑色,255表示白色.如有下图1:     图1                                                                                                                       图2 我们很难看清上述图1中的内容,原因是图片亮度太低,并且像素点之间相差较小,人眼难

OpenCV Tutorials &mdash;&mdash; Hough Line Transform

霍夫直线变换 -- 用于检测图像中的直线 利用图像空间和Hough参数空间的点--直线对偶性,把图像空间中的检测问题转换到参数空间,通过在参数空间进行简单的累加统计,然后在Hough参数空间中寻找累加器峰值的方法检测直线 Standard and Probabilistic Hough Line Transform OpenCV implements two kind of Hough Line Transforms: The Standard Hough Transform It consis

OpenCV Tutorials &mdash;&mdash; Feature Matching with FLANN

Extractors of keypoint descriptors in OpenCV have wrappers with a common interface that enables you to easily switch between different algorithms solving the same problem.   DescriptorExtractor::compute Computes the descriptors for a set of keypoints

OpenCV Tutorials &mdash;&mdash; Creating a video with OpenCV

写video 需要用到 VideoWriter  视频文件可看作一个容器 视频的类型由视频文件的后缀名来指定   Due to this OpenCV for video containers supports only the avi extension, its first version. A direct limitation of this is that you cannot save a video file larger than 2 GB. Furthermore you ca

OpenCV Tutorials &mdash;&mdash; Image Moments

图像矩 Moments moments(InputArray array, bool binaryImage=false ) Parameters: array – Raster image (single-channel, 8-bit or floating-point 2D array) or an array ( or ) of 2D points (Point or Point2f ). binaryImage – If it is true, all non-zero image pi

OpenCV Tutorials &mdash;&mdash; Hough Circle Transform

Hough 圆变换 和 Hough 直线变换原理相同,只是参数空间不同 : In the line detection case, a line was defined by two parameters . In the circle case, we need three parameters to define a circle: where define the center position (gree point) and is the radius, which allows us