灰度图像的求反、方根、平方、对数、指数和对比度运算(Matlab)

clc;
clear all;
img=im2double(imread('D:\Gray Files\3-4.tif'));
[M,N]=size(img);
%灰度图像取反
img_negative=1-img;
%方根运算
img_root=sqrt(img);
%平方运算
img_square=img.^2;
%对数运算
c=1;
img_log=c*log2(img+1);
%指数运算
gamma=5;
img_power=c*img.^gamma;
%分段运算,提高对比度
%得到最大图像灰度最大值
L=max(img(:));
img_contrast=zeros(M,N);
for i=1:M
    for j=1:N
        if img(i,j)>L*0.5
            img_contrast(i,j)=1.9*img(i,j);
        elseif img(i)>L*0.4
            img_contrast(i,j)=1.5*img(i,j);
        else
            img_contrast(i,j)=0.94*img(i,j);
        end
    end
end
subplot(3,4,1);
imshow(img);
title('原图');
%%取反运算
subplot(3,4,2);
imshow(img_negative);
title('求反');
%%%方根运算
subplot(3,4,3);
imshow(img_root);
title('方根');
%平方运算
subplot(3,4,4);
imshow(img_square);
title('平方');
%对数运算
subplot(3,4,5);
img_log_max=max(max(img_log));
img_log=img_log./img_log_max;
imshow(img_log);
title('对数');
%对数运算
subplot(3,4,6);
img_power_max=max(max(img_power));
img_power=img_power./img_power_max;
imshow(img_power);
title('指数');
%分段运算,提高对比度
subplot(3,4,7);
imshow(img_contrast);
title('对比度');

 

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