Automatic color scale, automatic contrast algorithm implementation

Source: Internet
Author: User
Tags ming

Introduction

Automatic color scale algorithm is used for image enhancement, fog and so on, the idea of removing the highest pixel value ratio, remove some of the lowest pixel value of the proportion, and then in the image of the rest of the pixel value of the linear mapping or gamma correction to the [0, 255] interval. For example, in the image processing is not very familiar?!

This article mainly refer to people on the journey of the blog, using the Matlab language implementation, the algorithm is not detailed description, this code left to do notes.

Code Autolevel:
function imdst = Autolevel (Varargin) [I, Lowcut,highcut] =parse_inputs (varargin{:}); [hei,wid,~] = size (I);Pixelamount= Wid * HEI;ifSizeI,3)==3[histred, ~] = Imhist (I(:,:,1)); [Histgreen, ~] = Imhist (I(:,:,2)); [Histblue, ~] = Imhist (I(:,:,3));cumred= Cumsum (histred);Cumgreen= Cumsum (Histgreen);Cumblue= Cumsum (Histblue); MinR =find (cumred>=Pixelamount*lowcut,1,' first '); MinG = Find (Cumgreen>=Pixelamount*lowcut,1,' first '); Minb =find (Cumblue>=Pixelamount*lowcut,1,' first '); MaxR =find (cumred>=Pixelamount*(1-highcut),1,' first '); Maxg =find (Cumgreen>=Pixelamount*(1-highcut),1,' first '); MAXB = Find (Cumblue>=Pixelamount*(1-highcut),1,' first ');Redmap= Linearmap (MINR,MAXR);Greenmap= Linearmap (MING,MAXG);Bluemap= Linearmap (MINB,MAXB); IMDST = Zeros (Hei,wid,3,' Uint8 '); IMDST (:,:,1) =Redmap(I(:,:,1)+1); IMDST (:,:,2) =Greenmap(I(:,:,2)+1); IMDST (:,:,3) =Bluemap(I(:,:,3)+1);Else   Histgray= Imhist (I(:,:));Cumgray= Cumsum (histred); Mingray =find (Cumgray>=Pixelamount*lowcut,1,' first '); Maxgray =find (Cumgray>=Pixelamount*(1-highcut),1,' first ');Graymap= Linearmap (Mingray,maxgray); IMDST = Zeros (Hei,wid,' Uint8 '); IMDST (:,:) =Graymap(I(:,:)+1);End%--------------------------------------------------------------------function map = linearmap (low,high) map = [0:1:255]; forI=0:255   if(i<low) Map (i+1) =0; ElseIf (I>high) map (i+1) =255;ElseMap (i+1) =uint8 ((I-low)/(high-low) *255);EndEnd%-------------------------------------------------------------------function [I, lowcut,highcut] = parse_inputs (varargin) Narginchk (1,3)I= varargin{1};validateattributes (I,{' Double ',' Logical ',' Uint8 ',' UInt16 ',' Int16 ',' single '},{},... Mfilename,' Image ',1);ifNargin = =1Lowcut =0.005; Highcut =0.005; ElseIf Nargin = =3Lowcut = varargin{2}; Highcut = varargin{3};ElseError (Message (' Images:im2double:invalidIndexedImage ',' single, or logical. '));End
Test Drive Code:
I = imread(‘bikes1.jpg‘);Out = autolevel(I,0.005,0.005); imshow([IOut])
Result one click to fog


Low illumination image enhancement, water-like enhancement

Evaluation

Automatic color scale used to do fog, or relatively stable, especially for the fog distribution uniformity, the effect is very good, the shortcomings are more obvious, can not be adaptive fog distribution, and channel separation calculation, some time will bring some color distortion phenomenon. There are also many other enhancement methods, such as dark channel fog, optimized contrast fog, based on color-lines fog, but these algorithms are not very stable, when the prior knowledge failure, processing distortion is more serious. Incidentally, the United States 美图秀秀 a key to the fog is the use of this method.
In addition, the automatic contrast algorithm and the automatic color scale and similar, you can refer to more content, not in detail here.

Read more

Http://www.cnblogs.com/Imageshop/archive/2011/11/13/2247614.html
http://blog.csdn.net/bluecol/article/details/45422653

Reprint please keep the following information
author Update Date Contact Information
The wind blows the summer May 8, 2015 [Email protected]

Automatic color scale, automatic contrast algorithm implementation

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.