[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppOpenCvHistogramEqualization
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppOpenCvHistogramEqualization
(C++ OpenCV) Histogram equalization
Technique to maximize contrast in an image.// Disclaimer: This code employs bad programming style // Please improve. I (Bilderbikkel) cannot do so, as I do not have // OpenCV installed on my computer anymore.void histogramEqualize(const IplImage * const pSource, IplImage * pTarget) { assert(pSource!=NULL); assert(pTarget!=NULL); assert(pSource->nChannels ==1); assert(pTarget->nChannels ==1); assert(pSource->width == pTarget->width); assert(pSource->height == pTarget->height); CvHistogram *hist; uchar lut[256]; double lut1[256]; CvMat* lut_mat; int hist_size = 256; float range_0[]={0,256}; float* ranges[] = { range_0 }; int high=0; int low =0; float hist_value = 0.0; hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1); lut_mat = cvCreateMatHeader( 1, 256, CV_8UC1 ); cvSetData( lut_mat, lut, 0 ); //cvCalcHist( &pSource, hist, 0, NULL ); cvCalcHist( const_cast<IplImage**>(&pSource), hist, 0, NULL ); //CUMULATIVE ARRAY lut1[0] = 0; for(int index = 0; index != hist_size; ++index) { hist_value = cvQueryHistValue_1D(hist,index); lut1[index+1]= lut1[index] + hist_value; } //CALCULATE THE NEW LUT float scale_factor; scale_factor = 255.0f / (float) (pSource->width * pSource->height); for (int index=0; index!=256; ++index) { lut[index]= (unsigned char)((float)lut1[index]*scale_factor); } //PERFORM IT ON THE CHANNEL cvLUT( pSource, pTarget, lut_mat ); cvReleaseMat( &lut_mat); cvReleaseHist(&hist); }
- include <cv.h>
Code links
'Histogram equalization' links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
