Image enhancement of low illumination based on dark primary color fog

Source: Internet
Author: User
a brief introduction to dark primary color fog

In the field of image fog, few people do not know that Dr. He Keming published in 2009 CVPR's best paper-"single Image Haze removal Using Dark Channel Prior", the article points out that in most non-sky local area, Some pixels always have at least one color channel with a very low value, that is, the region's light intensity is very small, for any input image? J, its dark channel can represent the following:

The C in the equation represents each channel of the RGB image, Ω (x) is expressed as the neighborhood of Pixel, first, the minimum value of RGB component of each pixel is obtained, and the image is stored in a grayscale image with the same size as the original one, then the minimum filter is made, and the radius of the filter is determined by the window size. Algorithm details here is not detailed, specific reference to the "single Image Haze removal Using Dark Channel Prior" paper, the following figure gives some of the dark colors to fog the paper effect.

two. Low illumination image enhancement based on dark primary color fog algorithm

Inspired by the dark color of the fog algorithm, the 2011 IMCE on the "FAST Efficient algorithm for enhancement of the low lighting video" proposed a dark primary color to fog the dim image enhancement algorithm, but I talents, The following video encoding this piece of content is not quite understood, so just talk about the previous for the single frame video low illumination enhancement of some principles and practice code.

It is pointed out that the image representation and histogram characterization of low illumination image, usually refers to the image which is dark or nighttime, and has a high similarity to the image before the fog.

As shown above, the first act of the night shot to get the picture, the second behavior after the rollover operation of the image, the third row is to go fog image, you can see that the second row and the third row in the image representation of a strong similarity. As can be seen from the straight square diagram, the two are basically similar. So we can try to use the low illumination image to flip, carry out fog operation, realize the effect of low illumination image enhancement.

For a low illuminance image, first flip the operation:

In computer vision, it is usually possible to model the images obtained from the photographing equipment as follows.

Where j is the real world image, T is the transmission rate, which refers to the ratio of the brightness in the real world image to the acquisition of the device, a refers to the global atmospheric composition, usually a constant. In this way, the problem becomes simple, so long as we can find the transmission T, then we can inverse the R and the above formula, then reverse the operation, we can get the enhanced image.

In the dark primary color fog algorithm, T is defined as the following form:

In code practice, a represents the channel values of all RGB three channels and the largest pixel points (where images are normalized to 0-1).

Finally, the image can be improved by inverse solution of the original image J and the image inversion of J.

The image is enhanced by the way of dark primary color fog removal, and the operation is simple and the effect is obvious.

The following is attached to the implementation of their own Python code, for everyone to exchange learning, not exactly in accordance with the paper, using the dark color to fog to follow up the subsequent acceleration of some strategies, enhance the effect is more acceptable, the specific use of the need to modify and debug.

Import CV2 Import NumPy as NP import datetime import time Def zmminfiltergray (SRC, r=7): if R <= 0:retur n src h, w = src.shape[:2] I = src res = np.minimum (i, i[[0] + range (h-1),:) res = Np.minimum (res, i[r Ange (1, h) + [h-1],:] I = Res res = np.minimum (I, i[:, [0] + range (w-1)) res = Np.minimum (res, i[:, ran 
    GE (1, w) + [w-1]]) return Zmminfiltergray (res, r-1) def guidedfilter (I, P, R, EPS): height, width = i.shape 
    M_i = Cv2.boxfilter (i,-1, (R, r)) m_p = Cv2.boxfilter (p,-1, (R, r)) M_ip = Cv2.boxfilter (i * p,-1, (R, R))  COV_IP = m_ip-m_i * m_p M_ii = cv2.boxfilter (i * I,-1, (R, r)) Var_i = M_ii-m_i * m_i a = COV_IP/ (Var_i + eps) b = m_p-a * M_i m_a = Cv2.boxfilter (A,-1, (R, r)) M_b = Cv2.boxfilter (b,-1, (R, R)) re Turn m_a * I + m_b def getV1 (M, R, EPs, W, maxV1): V1 = Np.min (M, 2) V1 = Guidedfilter (V1, Zmminfiltergray (V1, 7 ), R, eps) bins = 20HT = Np.histogram (V1, bins) d = np.cumsum (ht[0])/float (v1.size) for Lmax in range (bins-1, 0,-1): If D[lmax] <= 0.999:break A = Np.mean (M, 2) [V1 >= ht[1][lmax]].max () V1 = Np.minimum (V1 * W
    , maxV1) return V1, A def dehaze (M, r=81, eps=0.001, w=0.6, maxv1=0.80, bgamma=false): Y = Np.zeros (M.shape) V1, A = getV1 (M, R, EPs, W, maxV1) for K in range (3): y[:,:, K] = (m[:,:, K]-V1)/(1-v1/a) Y =
    Np.clip (y, 0, 1) If bgamma:y = y * * (Np.log (0.5)/Np.log (Y.mean ())) return Y def Image_convet (IMG): img[:,:,:] = 255-img[:,:,:] return img If __name__ = ' __main__ ': start = Time.clock () img = Cv2.imre AD ('/users/xxx/desktop/yeecall/low_lighting_video/test1.png ') img = Cv2.resize (IMG, (640)) img = Image_convet (img) m = dehaze (img/255.0) * 255 m = Image_convet (m) end = Time.clock () print End-start Cv2.imwrit E (' 666.jpg ', m)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.