0
$\begingroup$

I have a C# desktop application. I am using EMGU as a wrapper for OpenCV.

I am receiving images in JPEG format that were originally taken by an analogue camera.

The quality of the image is poor (compared to digital cameras).

I want to see if I can use filters/methods derived from OpenCV/EMGU that could enhance the image.

What I mean by enhancement is to make the image a bit sharper.

I have played around with median, bilateral, contrast stretching to see if the image can be improved.

Nothing has worked.

Even if it can be confirmed to me that nothing I can do will enhance the image that will be an answer in itself. I can stop trying and persuade the client to use a digital camera instead...

This is the image:

grainy image

This is the code that I apply to the original image to get the image you can see here:

        int factor = Shared.factor;
        int xVal = 288;
        int yVal = 360;
        using (Image<Bgr, Byte> color = new Image<Bgr, byte>(grid))
        {
            byte[] data = null;

              for (int x = 0; x < xVal; x++)
              {
                  for (int y = 0; y < yVal; y++)
                  {
                      grid[x, y, 0] = (byte)(grid[x, y, 0] / factor);
                      grid[x, y, 1] = (byte)(grid[x, y, 1] / factor);
                      grid[x, y, 2] = (byte)(grid[x, y, 2] / factor);
                  }
                }
                color.Data = grid;
                data = ImageToByteArray(color.ToBitmap());
        }


    private byte[] ImageToByteArray(Image imageIn)
    {
        byte[] data = null;
        try
        {
            using (MemoryStream ms = new MemoryStream())
            {
                imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                imageIn.Dispose();
                data = ms.ToArray();
            }
        }
        catch (Exception ex)
        {
         //do something
        }
        finally
        {
            if (imageIn != null)
            {
                imageIn.Dispose();
            }
        }
        return data;
    }

As requested this is an original image but from a different view:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Does the camera really perform that badly, or are you seeing scanner artifacts? The attached image has a high JPEG quality (94) but it looks as though it has been a much lower quality somewhere in the work flow. $\endgroup$ – Glenn Randers-Pehrson Mar 27 '14 at 15:37
  • $\begingroup$ @GlennRanders-Pehrson Hi Glenn, you are quite right i am ultimately uploading the image to my server as a byte array. If I upload it as I get it it will be 28K worth of bytes. To increase the upload time I load the image into an EMGU image and I divide the triple data array by a factor 2. (I can provide code). This reduces the byte array to approx. 12K. I then 'decompress' the image on the server by reversing the process and this image is the result of that process. I cannot use a video codec for various reasons and this is the only way I get near enough real-time streaming. $\endgroup$ – Andrew Simpson Mar 27 '14 at 16:55
  • 1
    $\begingroup$ What sort of frame grabber are you using to acquire the image? I've used analog cameras in the (distant) past for automated optical inspection, and never seen image quality quite so poor. If the analog image displays well in analog, then the problem is usually your frame grabber (image digitizer). $\endgroup$ – Peter K. Mar 27 '14 at 18:46
  • $\begingroup$ @PeterK. Hi, thanks for taking an interest in this. I am using a wrapper for VLC - nvlc (which I got from CodeProject). I did try to make it work with emgu/opencv but it would not pick up my rtsp feed. I did also try to make it work with VLC 64 bit but I got no feed at all. The cameras ARE of poor quality. But the degradation is not helped by my code (edited question). I am just looking at everything and anything I can think of to reduce the upload data.. $\endgroup$ – Andrew Simpson Mar 27 '14 at 18:56
  • $\begingroup$ Can you add an image that doesn't use your scaling, so we can see what the effect is? $\endgroup$ – Peter K. Mar 27 '14 at 19:00
2
$\begingroup$

There is no way to regain any lost data at all. However, there are many phenomena that might distort the image in a recoverable way, not actually losing any data. You seem to try to undo a "point spread function", that is eg. some consistent blur. This would be not the only way an image can be distorted, however it is by far the most common.

In that case you would assume that the original image is convolved or filtered by an (initially unknown) point spread function. There may be the inverse operation to that. You could call this "equalization" of the frequency space of the image, then.

Not every inverse operation would be represented by an "edge sharpening" operation that is known a priori. You could maybe try to look at the image a virtually point-shaped light source gives, preferrably in front of a dark background. A laser pointer or a bright LED might serve as an example.

$\endgroup$
  • 1
    $\begingroup$ Hi, this is a very informative answer. I am still learning all this so not sure how to derive a practical solution from this. But it will eventually make sense to me $\endgroup$ – Andrew Simpson Mar 27 '14 at 16:57
1
$\begingroup$

Your image seems sharp. Increasing the sharpness will not help. You need to use Deconvolution to inpaint some of the missing data. Try algorithms for inpainting, low-rank + sparse recovery or other methods of compressed sensing. If you want to increase the resolution then you can use the algorithms of super resolution, try the following http://www.wisdom.weizmann.ac.il/~vision/SingleImageSR.html

$\endgroup$
  • $\begingroup$ Thank you so much for that link. I need to go through it and see if I can write C# for it. I will comment back - thanks $\endgroup$ – Andrew Simpson Mar 27 '14 at 19:41

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.