码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV Tutorials —— Histogram Equalization

时间:2014-11-21 18:36:44      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   os   sp   for   on   

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

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

bubuko.com,布布扣

bubuko.com,布布扣

 

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

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

    To use this as a remapping function, we have to normalize bubuko.com,布布扣 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:

    bubuko.com,布布扣

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

    bubuko.com,布布扣

 

 

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;
}

 

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

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

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

OpenCV Tutorials —— Histogram Equalization

标签:style   http   io   ar   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/sprint1989/p/4113390.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!