Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
OPENCV Topic 03 - Histogram Equalization

OPENCV Topic 03 - Histogram Equalization

Ratings: (0)|Views: 638|Likes:
Published by huahongquan2007

More info:

Categories:Types, School Work
Published by: huahongquan2007 on Sep 23, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/07/2014

pdf

text

original

 
MAIN.CPP
#include <iostream>  using namespacestd; #include "histogram.h"  voidmain(){cv::Mat img = cv::imread("pic.jpg");cv::Mat img_gray;cvtColor(img,img_gray,CV_RGB2GRAY);// easy way to have grayscale :) cv::Mat img_new = img_gray.clone();intgrayLevel = 256;//HISTOGRAM Histogram1D h;cv::MatND histogram = h.getHistogram(img_gray);//HISTOGRAM BEFORE EQUALIZATION cv::namedWindow("Histogram Before");cv::imshow("Histogram Before",h.getHistogramImage(img_gray));// IMAGE BEFORE cv::namedWindow("My Image Before");cv::imshow("My Image Before",img_gray);//------------------------------------------------ // EQUALIZATION float* pr =new float[grayLevel]; floatn = img_gray.rows * img_gray.cols;for(inti = 0 ; i < grayLevel ; i++) {floatnk = histogram.at<float>(i); pr[i] = nk / n;}for(inti = 1 ; i < grayLevel ; i++) {pr[i] = pr[i - 1] + pr[i];}for(inti = 0 ; i < img_new.rows ; i++) {uchar* data = img_new.ptr<uchar>(i);for(intj = 0 ; j < img_new.cols ; j++) {intgrayValue = (int)data[j * img_new.channels() + 0 ]; floatval = pr[ grayValue ] * ( grayLevel - 1 );data[j * img_new.channels() + 0 ] = val ;}
 
}//------------------------------------------------ // HISTOGRAM AFTER cv::namedWindow("Histogram After");cv::imshow("Histogram After",h.getHistogramImage(img_new));//---Image After cv::namedWindow("My Image After");cv::imshow("My Image After",img_new);cv::waitKey(0);}
Histogram.h
#ifndef_HISTOGRAM#include <opencv2\core\core.hpp>  #include <opencv2\highgui\highgui.hpp>  #include <opencv2\imgproc\imgproc.hpp> // -> cvtColor  classHistogram1D{private:inthistSize[1];//number of bins  floathranges[2];//min & max pixel value  const float* ranges[1]; intchannels[1];// only 1 channels  public:Histogram1D(){// Prepare arguments for 1D histogram histSize[0] = 256;hranges[0] = 0.0;hranges[1] = 255.0;ranges[0] = hranges;channels[0] = 0;}// get Histogram cv::MatND getHistogram(constcv::Mat &image){cv::MatND hist;//compute histogram cv::calcHist(&image,1,// 1 image only channels,//channels cv::Mat(),// no mask hist,// the result 1,// 1D histogram histSize,// number of bins ranges// pixel value range );returnhist;}cv::Mat getHistogramImage(constcv::Mat &image)

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->