I want to perform contrast stretching on an image. The image is as shown (The data-tips are created by me in MATLAB to give more information about the image, the timestamp is already there on the image).
Now, how to perform contrast stretching has already been described here. But that formula won't work here since imgMin=0
and imgMax=255
. So the image would remain unchanged. So my workaround was local contrast stretching. I am unsure as to how to do this (and also relatively fast i.e. I should be able to contrast stretch frames of video and still play video in realtime. I tried histogram equalization, though it produces realtime results in OpenCV, the contrast stretching is not impressive). To understand if the algorithm is working, I am also open to the use of MATLAB.
I have also shown datatips where you can see the pixel values. I have converted my color image into gray-scale first. In short, the aim is white lanes should become brighter though brightest part of the image takes value 255 (i.e. the sun).
You might get the results you are looking for with detail enhancement filters, using a large filter radius. A popular example of detail enhancement is the "Clarity" effect in Adobe Lightroom. What these algorithms do actually amounts to increasing contrast locally.
The Guided Filter can be used for detail enhancement (see page 10 of the linked paper), and it may be sufficiently fast for video, in contrast to the better known Bilateral Filter. It is also relatively easy to implement, at least for grayscale images or for per-channel operation. Matlab code for experimenting is here, it contains a detail enhancement example, if I recall correctly.
Theory: Roughly, the idea is to add a high-pass filtered version of the image to the original image. If you do this with a small high-pass kernel you do sharpening, if you use a large kernel (letting through more frequencies) you do detail enhancement. The Guided Filter is a clever method of avoiding halo artifacts which occur at sharp light-to-dark boundaries when you approach the problem with simple high-pass filters.