logo       
Bookmark and Share

Re: Problem equalizing the histogram of an image: msg#00652

lib.opencv

Subject: Re: Problem equalizing the histogram of an image

Hi visnavki,

There is a Histogram equalisation function in opencv, which you can
use if you wish.

It is:

------------
EqualizeHist
------------

Equalizes histogram of grayscale image

void cvEqualizeHist( const CvArr* src, CvArr* dst );

src
The input 8-bit single-channel image.
dst
The output image of the same size and the same data type as src.

The function cvEqualizeHist equalizes histogram of the input image
using the following algorithm:

1. calculate histogram H for src.
2. normalize histogram, so that the sum of histogram bins is 255.
3. compute integral of the histogram:
H'(i) = sum0≤j≤iH(j)
4. transform the image using H' as a look-up table: dst(x,y)=H'(src(x,y))

The algorithm normalizes brightness and increases contrast of the image.


For example, consider this code:
=======================================================================

// Load the color image into a temporary file
IplImage* temp = cvLoadImage( "flower.jpeg", -1 );

// src is the grayscale image, and dst is the equalized image
IplImage *src = cvCreateImage( cvGetSize( temp ), IPL_DEPTH_8U, 1 );
IplImage *dst = cvCreateImage( cvGetSize( temp ), IPL_DEPTH_8U, 1 );

// Convert the image into a grayscale image
cvCvtColor( temp, src, CV_BGR2GRAY );

// Release the temp, which is not necessary hereafter
cvReleaseImage( &temp );

// Histogram Equalization
cvEqualizeHist( src, dst );

// Show the GrayScale image
cvNamedWindow( "Grayscale", 1);
cvShowImage( "Grayscale", src );

// Show the Histogram Equalized image
cvNamedWindow( "Equalized", 1 );
cvShowImage( "Equalized", dst );
=======================================================================

Regards, :D
Paramesh.

--- In OpenCV@xxxxxxxxxxxxxxx, "visnavki" <visnavki@xxxx> wrote:
>
> Hey folks,
>
> I hope someone of you can help me regarding my concern. The code I'm
> using for implementing an histogram equalization is shown below. But
> it does not work in any sense. Curious to me is, that even the
> max_value variable does not contain a reasonable value, so something
> must go wrong when calculating the histogram itself. But I am unable
> to locate the point of failure.
>
> Here's the code:
> **********************************
> IplImage* iplGrayScaleImg = cvCreateImage(cvGetSize(input_image),
> IPL_DEPTH_8U, 1);
> IplImage* iplGrayScaleImgOrg = cvCloneImage(iplGrayScaleImg);
>
> int iNumOfDims = 1;
> int iDimSizes = 256;
> float fRange_0[] = {0,256};
> float* fRanges[] = {fRange_0};
> CvHistogram* cvhImgHist = cvCreateHist(iNumOfDims, &iDimSizes,
> CV_HIST_ARRAY, fRanges, 1);
> cvCalcHist(&iplGrayScaleImg, cvhImgHist, 0, 0);
>
> uchar ucLutData[256];
> CvMat* cvmLut = cvCreateMatHeader(1, 256, CV_8UC1);
>
> float max_value=0.0;
> cvGetMinMaxHistValue(cvhImgHist, 0, &max_value, 0, 0);
>
> int i,j;
> int iQ = 256;
> long iSum;
> for(i=0; i<iDimSizes; i++)
> {
> iSum = 0;
> for(j=0; j<=i; j++)
> {
> iSum += (long)(cvQueryHistValue_1D(cvhImgHist, j));
> }
> ucLutData[i] =
> (uchar)((iQ-1)*iSum/(iplGrayScaleImg->width*iplGrayScaleImg->height));
> }
>
> cvSetData(cvmLut, &ucLutData, 0);
>
> cvLUT(iplGrayScaleImgOrg, iplGrayScaleImg, cvmLut);
>
> output_image = cvCloneImage(iplGrayScaleImg);
> **********************************
>
> Thanks for help in advance,
>
> Chris
>







Change settings: http://www.yahoogroups.com/mygroups, select
Get Emails (get all posts)
Daily Digest (one summary email per day)
Read on the web (read posts on the web only)Or Unsubscribe by mailing
OpenCV-unsubscribe@xxxxxxxxxxxxxxx



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise