Photoshop图像处理算法—自动对比度和自动色调(自动色阶)

1、原理部分

Photoshop图像处理算法—自动对比度和自动色调(自动色阶)_第1张图片

Photoshop图像处理算法—自动对比度和自动色调(自动色阶)_第2张图片


2、程序部分(matlab)

 自动色调

clc;clear;close all;
img=imread('IMG_0950_cut.jpg');
Image=double(img)/255;
figure(1);
imshow(Image);
%%  
R=Image(:,:,1);
G=Image(:,:,2);
B=Image(:,:,3);
percent=0.001;
%% 
Image_out(:,:,1)=Auto_Tune(R, percent);
Image_out(:,:,2)=Auto_Tune(G, percent);
Image_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 value
I_sort=sort(I(:));
I_out=I;

%%% based on the clipping percentage, 
%%% compute 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)))
end

for i=1:row
    for j=1:col
            if(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

-----------------------------------------------------------------------------

自动对比度

%运行文件
clc;clear;close all;
img=imread('lena.jpg');
Image=double(img)/255;
figure(1);
imshow(Image);
%%  
R=Image(:,:,1);
G=Image(:,:,2);
B=Image(:,:,3);
percent=0.001;
%获得各个通道的最大最小值
[R_max,R_min] = findMaxMin(R,percent);
[G_max,G_min] = findMaxMin(G,percent);
[B_max,B_min] = findMaxMin(B,percent);
%求出统一的最大最小值
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);


%求出各个通道的按照比例裁切的最大最小值
function [I_max,I_min] = findMaxMin(I,percent )
%%%sort the input image value
I_sort=sort(I(:));
[row, col]=size(I);
%%% based on the clipping percentage, 
%%% compute 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)));
end

end


%根据统一的最大最小值进行变换

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)Max)
                I_out(i,j)=1;
            else
                I_out(i,j)=(I(i,j)-Min)/(Max-Min);
            end
    end 
end

3、运行结果
Photoshop图像处理算法—自动对比度和自动色调(自动色阶)_第3张图片

图1 原图

Photoshop图像处理算法—自动对比度和自动色调(自动色阶)_第4张图片

图 2 自动对比度

Photoshop图像处理算法—自动对比度和自动色调(自动色阶)_第5张图片

图 3 自动色调

你可能感兴趣的:(图像处理)