1. Principle part
2. Program part (MATLAB)
Auto Tone
Clc;clear;close all;img=imread (' img_0950_cut.jpg '); Image=double (IMG)/255;figure (1); Imshow (Image); Percent R=image (:,:, 1); G=image (:,:, 2); B=image (:,:, 3);p ercent=0.001;%% image_out (:,:, 1) =auto_tune (R, percent); Image_out (:,:, 2) =auto_tune (G, percent); I Mage_out (:,:, 3) =auto_tune (B, percent); figure (2); Imshow (image_out);
function I_out=auto_tune (I, percent)%%% the tonal range of the input image is 0-1. [Row, Col]=size (i);%%%sort the input Image valuei_sort=sort (I (:)); i_out=i;%%% based on the clipping percentage,%%% comput E the upper and lower boundaries if (percent==0) i_min=min (i_sort) I_max=max (i_sort) Else I_min=i_sort ( Floor (row*col*percent)) I_max=i_sort (Floor (row*col* (1-percent))) ENDfor I=1:row for j=1:col if (I (I,J) <i_min) i_out (i,j) =0; ElseIf (I (i,j) >i_max) i_out (i,j) =1; else i_out (i,j) = (I (i,j)-i_min)/(i_max-i_min); End End End
-----------------------------------------------------------------------------
Automatic contrast ratio
% Run File
Clc;clear;close all;img=imread (' lena.jpg '); Image=double (IMG)/255;figure (1); Imshow (Image); Percent R=image (:,:, 1); G=image (:,:, 2); B=image (:,:, 3);p ercent=0.001;% to obtain the maximum minimum value for each channel [r_max,r_min] = Findmaxmin (r,percent); [G_max,g_min] = Findmaxmin (g,percent); [B_max,b_min] = Findmaxmin (b,percent);% to find a uniform maximum minimum value Max=max (max (R_max,g_max), B_max); Min=min (min (r_min,g_min), b_min); Image_out (:,:, 1) =auto_tune (r,max,min); Image_out (:,:, 2) =auto_tune (g,max,min) ; Image_out (::, 3) =auto_tune (b,max,min); figure (2); Imshow (image_out);
% to find the maximum minimum value of each channel cut by proportion
function [I_max,i_min] = Findmaxmin (i,percent)%%%sort the input image Valuei_sort=sort (I (:)); [ Row, Col]=size (I);%%% based on the clipping percentage,%%% compute the upper and lower boundaries if (percent==0) i_m In=min (i_sort); I_max=max (I_sort); else i_min=i_sort (Floor (row*col*percent)); I_max=i_sort (Floor (row*col* (1-percent))); EndEnd
% is transformed according to the uniform Maximum minimum value
function I_out=auto_tune (i,max,min)%%% the tonal range of the input image is 0-1. [Row, Col]=size (i); i_out=i;for i=1:row for j=1:col if (i (I,J) <min) i_out (i,j) =0; ElseIf (I (i,j) >max) i_out (i,j) =1; else i_out (i,j) = (I (i,j)-min)/(max-min); End End End
3. Operation Result
Figure 1 Original
Figure 2 Automatic contrast ratio
Figure 3 Auto Tone
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Photoshop image processing Algorithms-auto contrast and auto tone (auto levels)