opencv直方图均衡化
#include <iostream>
#include "highgui.h"
#include "cv.h"
#include "cxcore.h"
#include "math.h"
using namespace std;
using namespace cv;
//绘制1维直方图
Mat draw1DHistogram(Mat histogramMat) {
double maxVal = 0, minVal = 0;
minMaxLoc(histogramMat, &minVal, &maxVal, 0, 0);
Mat histImage(histogramMat.rows, histogramMat.rows, CV_8U, Scalar(255));
int hpt = static_cast<int>(0.9 * histogramMat.rows);
for (int h = 0; h < histogramMat.rows; h++) {
float binVal = histogramMat.at<float>(h);
int intensity = static_cast<int>((binVal / maxVal) * hpt);
line(histImage, Point(h, histogramMat.rows - 1),
Point(h, histogramMat.rows - 1 - intensity), Scalar::all(0));
}
return histImage;
}
//一维直方图计算(采用实际图像) 实验2
void get1DHistogramExperiment2(Mat& image) {
//计算直方图 使用的图片数量
int nImageArrays = 1;
//使用的直方图数组
Mat* imageArrays = new Mat[nImageArrays];
//加载实际图像
// Mat image = imread("e:\\citywall1.bmp", 0);
if (image.data == NULL) {
printf("加载图像失败\n");
return;
}
imageArrays[0] = image;
//直方图的维数
const int dims = 1;
//在图像的通道序列中 本次直方图计算使用了哪些通道,本代码中使用了编号为0的通道
int channels[dims] = { 0 };
//直方图中每一维上的bin数,本代码是创建一维直方图 并且 分为256个bin
int histBins[dims] = { 256 };
//保存直方图的结果 CV_32F,dims说明矩阵的维度,histBins说明矩阵每一维上的大小
Mat histND(dims, histBins, CV_32F, Scalar::all(0));
//手动指定各个bin的取值范围
//float image1Range[5]={0.0,50.0,200.0,220.0,256.0};
//统一分割,只需要指定bin[0]的下限值和bin[histBins[dims-1]-1]的上限值即可
float image1Range[5] = { 0.0, 256.0 };
//各个通道的 bin划分规则
const float* allRanges[dims] = { image1Range };
//直方图计算
calcHist(imageArrays, nImageArrays, channels, Mat(), histND, dims, histBins,
allRanges, true);
//绘制直方图
Mat histImage = draw1DHistogram(histND);
//显示直方图
namedWindow("hist");
imshow("hist", histImage);
waitKey(0);
}
/**
* 直方图均衡
*/
void HistogramEqual(Mat& src){
Mat dst;
equalizeHist(src,dst); //直方图均衡化
get1DHistogramExperiment2(dst);
namedWindow("equal");
imshow("equal",dst);
waitKey(0);
}
int main() {
Mat image = imread("e:\\test.bmp", CV_LOAD_IMAGE_GRAYSCALE);
namedWindow("src");
imshow("src",image);
get1DHistogramExperiment2(image);
HistogramEqual(image);
return 0;
}
opencv直方图均衡化的更多相关文章
- OpenCV——直方图均衡化(用于图像增强)
#include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespac ...
- opencv::直方图均衡化
直方图均衡化 图像直方图: 是指对整个图像像在灰度范围内的像素值是指对整个图像像在灰度范围内的像素值(~)统计出现频率次数,据此生成的直方图,称为图像直方图-直方图. 直方图反映了图像灰度的分布情况. ...
- OpenCV-Python教程(10、直方图均衡化)
相比C++而言,Python适合做原型.本系列的文章介绍如何在Python中用OpenCV图形库,以及与C++调用相应OpenCV函数的不同之处.这篇文章介绍在Python中使用OpenCV和NumP ...
- opencv 彩色图像亮度、对比度调节 直方图均衡化
直接上代码: #include <Windows.h> #include <iostream>// for stand I/O #include <string> ...
- OpenCV图像增强算法实现(直方图均衡化、拉普拉斯、Log、Gamma)
http://blog.csdn.net/dcrmg/article/details/53677739 1. 基于直方图均衡化的图像增强 直方图均衡化是通过调整图像的灰阶分布,使得在0~255灰阶 ...
- 直方图均衡化的 C++ 实现(基于 openCV)
这是数字图像处理课的大作业,完成于 2013/06/17,需要调用 openCV 库,完整源码和报告如下: #include <cv.h> #include <highgui.h&g ...
- opencv图像直方图均衡化及其原理
直方图均衡化是什么有什么用 先说什么是直方图均衡化,通俗的说,以灰度图为例,原图的某一个像素为x,经过某个函数变为y.形成新的图.新的图的灰度值的分布是均匀的,这个过程就叫直方图均衡化. 图像直方图均 ...
- opencv 5 图像转换(3 重映射 仿射变换 直方图均衡化)
重映射 实现重映射(remap函数) 基础示例程序:基本重映射 //---------------------------------[头文件.命名空间包含部分]------------------- ...
- opencv —— equalizeHist 直方图均衡化实现对比度增强
直方图均匀化简介 从这张未经处理的灰度图可以看出,其灰度集中在非常小的一个范围内.这就导致了图片的强弱对比不强烈. 直方图均衡化的目的,就是把原始的直方图变换为在整个灰度范围(0~255)内均匀分布的 ...
随机推荐
- BZOJ 1911 特别行动队
另一个版本的斜率优化...这个要好理解一些. #include<iostream> #include<cstdio> #include<cstring> #incl ...
- HDU 5371 Hotaru's problem (Manacher,回文串)
题意:给一个序列,找出1个连续子序列,将其平分成前,中,后等长的3段子序列,要求[前]和[中]是回文,[中]和[后]是回文.求3段最长为多少?由于平分的关系,所以答案应该是3的倍数. 思路:先Mana ...
- activiti 源码笔记之startProcess
rumtimeService.startProcessInstanceByXX方法将启动流程的任务委派给StartProcessInstanceCmd,此时会根据rumtimeService.star ...
- linux下系统启动时,几个配置文件 /etc/profile、~/.bash_profile 等几个文件的执行过程,先后顺序
1. 在登录Linux时要执行文件的过程如下: 在刚登录Linux时, 首先启动 /etc/profile 文件, 然后再启动用户目录下的 ~/.bash_profile. ~/.bash_login ...
- Python [Leetcode 121]Best Time to Buy and Sell Stock
题目描述: Say you have an array for which the ith element is the price of a given stock on day i. If you ...
- MySQL内存表-临时表
HEAP表是访问数据速度最快的MySQL表,他使用保存在内存中的散列索引.但如果MySQL或者服务器重新启动,表中数据将会丢失.用法:如论坛的在线人数统计,这种表的数据应该是无关紧要的,就几个简单的字 ...
- UIPanGestureRecognizer中translationInView的理解
原因是在破船大牛的blog上面看到了一个demo #import <UIKit/UIKit.h> @interface ViewController : UIViewController ...
- linux各种查看端口号
1. 查看端口占用情况的命令:lsof -i [root@www ~]# lsof -i COMMAND PID USER FD TYPE DEVICE SIZE NODE N ...
- Java中传值与传引用
不管Java参数类型是什么,一律传递参数的副本. <Thinking In Java>:“When you're passing primitives into a method,you ...
- Fidder 监控WCF
Client端配置 <?xml version="1.0" encoding="utf-8" ?> <configuration> &l ...