- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello All,
I am trying to perform Auto Contrast in my grey images using Intel IPP functions. I am not sure where I am going wrong but the image becomes too dark. Here is the code.
#define GrayLevels 256
int main()
{
std::string path("C:\\sharath\\Images\\");
std::string inputImageFile = path + "DiffFing.bmp";
IppImage<Ipp8u,1> imgsrc;
ippiLoadBMP(inputImageFile.c_str(),imgsrc);
IppImage<Ipp8u,1> imgDst;
IppiSize imgSize;
Ipp32s imgLevels[GrayLevels+1], imgHist[GrayLevels];
Ipp32s imgValues[GrayLevels];
int w = imgsrc.Width();
int h = imgsrc.Height();
int nlevels = GrayLevels;
float ww=0;
int min=0;
int max=GrayLevels-1;
int slope;
float cut_low = 0.05f;
float cut_high = 0.95f;
imgSize.width = w;
imgSize.height = h;
ippiHistogramEven(imgsrc, imgSize, imgHist, imgLevels, GrayLevels+1, 0, GrayLevels);
while(ww<cut_low)
{
ww+=imgHist[min++];
}
while(ww<cut_high)
{
ww+=imgHist[max--];
}
slope = (GrayLevels-1)/(max-min);
for(int i=0;i<GrayLevels;i++)
{
if(i<=min)
{
imgValues = 0;
}
else if(i>=max)
{
imgValues = GrayLevels-1;
}
else
{
imgValues = slope*(i-min);
}
}
imgDst.ResizeNE(imgsrc.Width(),imgsrc.Height());
ippiLUT(imgsrc, imgDst, imgSize, imgValues, imgLevels, GrayLevels+1);
std::string out4f = path + "DiffFing_Auto.bmp";
ippiSaveBMP(out4f.c_str(),imgDst);
return(EXIT_SUCCESS);
}
Can somebody help me figure out why my image gets darker instead of enhancing the contrast.
I have also attached the files for reference. DiffFing_AutoContrast.bmp is the image after autocontrast.
Thanks,
Sharath
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the while-statement,
while(ww<cut_low)
{
ww+=imgHist[min++];
}
If I'm not mistaken, there is an error in datatype; ww is accumulating 32s values from imgHist, but cut_low is expressed in percentile, so a proper way would be to first compute the sum of all imgHist bins as 64u, and then have ww also as 64u, with value computed from sum*percentile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page