# Improve contrast when image has a flood of white balancing

I have an image taken a night time.

I apply _EqualizeHist to it. But the result is a high level of whiteness running through the image.

This is the image:

I had asked this question in a slightly different way and was given a link to improve the white balancing of the image.

This was the original question

I have got as far as this in my code but now I am stuck as to what to do next. I would be grateful if anyone can suggest the next step?

This is my code:

            Image<Bgr, byte> frame = new Image<Bgr, byte>(file);
frame._EqualizeHist();
Image<Hsv, byte> hsv = new Image<Hsv, byte>(file);
Image<Gray, byte> maskDark = new Image<Gray, byte>(hsv.Width, hsv.Height);

Bgr bgrLightest;
MCvScalar scalarLightest;

Bgr bgrDarkest;
MCvScalar scalarDarkest;


UPDATE: I have tried to implement the suggestion kindly goven by sansuiso.

This is the code:

 Image<Bgr, byte> rgb = new Image<Bgr, byte>(@"D:\789.jpg");
pictureBox1.Image = rgb.ToBitmap();

for (int x = 0; x < 360; x = x + 24)
{
for (int y = 0; y < 288; y = y + 24)
{
rgb.ROI = new Rectangle(0, 0, 360, 288);
int xx = x;
int yy = y;
if (x > 0)
{
xx = xx - 12;
}
if (y > 0)
{
yy = yy - 12;
}
rgb.ROI = new Rectangle(xx, yy, 24, 24); //360*288
rgb._EqualizeHist();
}
}
rgb.ROI = new Rectangle(0, 0, 360, 288);
pictureBox2.Image = rgb.ToBitmap();


And this is the resulting image:

Obviously, I am not doing this right. Can anyone see if my code is wrong please?

Histogram equalization is a global operation which can result in some areas being adversely effected at the cost of the rest of the image looking better. Consider using the Retinex algorithm. It works very well at improving both local and global contrast enhancement. There's a flurry of papers on this topic and the algorithm is somewhat straightforward to implement. The most challenging part is the selection of parameters.

Here's a list of papers and here's one that's very useful.

• Hi, sorry for the late reply.I shall take a look at this approach - thanks – Andrew Simpson Mar 22 '14 at 10:17
• meant to add 'and report back' :) – Andrew Simpson Mar 22 '14 at 12:51
• hi, this looked the most promising but I copied the c# code to my app and I just get a white image returned. I think I need to understand the solution proposed better so that I can understand how to implement it. Not unless you have the c# code working yourself? – Andrew Simpson Mar 22 '14 at 19:01
• You need to remap the results back into the 0-255 domain after the operation. – porten Mar 28 '14 at 3:19

You can perform histogram equalization on blocks inside the image. Overlapping blocks (and result averaging in the overlap areas) could help in reducing the subsequent block artifacts. R. Szeliski's book has some explanation of this local equalization algorithm.

Another possibility is to model the hotspot in the middle as a kind of Gaussian spot, then output the final result as the weighted mean between the original and equalized image. The weights should be given in each pixel by the value of this Gaussian spot. This is a crude model but that could give interesting results here.

• Hi, sorry for the late reply.I shall take a look at this approach - thanks – Andrew Simpson Mar 22 '14 at 10:17