1
$\begingroup$

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:

enter image description here

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

This is that link:

enter link description here

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> maskLight= new Image<Gray,byte>(hsv.Width,hsv.Height);
            Image<Gray, byte> maskDark = new Image<Gray, byte>(hsv.Width, hsv.Height);

            Emgu.CV.CvInvoke.cvThreshold(hsv[2], maskLight, 128, 255, THRESH.CV_THRESH_BINARY);
            Emgu.CV.CvInvoke.cvThreshold(hsv[2], maskDark, 0, 127, THRESH.CV_THRESH_BINARY);

            Bgr bgrLightest;
            MCvScalar scalarLightest;
            frame.AvgSdv(out bgrLightest, out scalarLightest, maskLight);

            Bgr bgrDarkest;
            MCvScalar scalarDarkest;
            frame.AvgSdv(out bgrDarkest, out scalarDarkest, maskDark);

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:

enter image description here

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

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Hi, sorry for the late reply.I shall take a look at this approach - thanks $\endgroup$ – Andrew Simpson Mar 22 '14 at 10:17
  • $\begingroup$ meant to add 'and report back' :) $\endgroup$ – Andrew Simpson Mar 22 '14 at 12:51
  • $\begingroup$ 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? $\endgroup$ – Andrew Simpson Mar 22 '14 at 19:01
  • $\begingroup$ You need to remap the results back into the 0-255 domain after the operation. $\endgroup$ – porten Mar 28 '14 at 3:19
1
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.