1.灰度变换增强程序:
% GRAY TRANSFORM
clc;
I=imread('pout.tif');
imshow(I);
J=imadjust(I,[0.3 0.7],[0 1],1);
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],0.5);
%output values.
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],1.5); % if GAMMA is greater than 1,the mapping si weighted toward lower (darker)
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],1.5);
%output values.
figure;
imshow(J)
J=imadjust(I,[0.3 0.7],[0 1],1); % If TOP<BOTTOM,the output image is reversed,as in a photographic negative.
figure;
imshow(J);
figure;
imshow(J)
J=imadjust(I,[0.3 0.7],[0 1],1);
figure;
imshow(J);
2.直方图灰度变换
%直方图灰度变换
[X,map]=imread('forest.tif');
I=ind2gray(X,map);%把索引图像转换为灰度图像
imshow(I);
title('原图像');
improfile%用鼠标选择一条对角线,显示线段的灰度值
figure;subplot(121)
plot(0:0.01:1,sqrt(0:0.01:1))
axis square
title('平方根灰度变换函数')
subplot(122)
maxnum=double(max(max(I)));%取得二维数组最大值
J=sqrt(double(I)/maxnum);%把数据类型转换成double,然后进行平方根变换
%sqrt函数不支持uint8类型
J=uint8(J*maxnum);%把数据类型转换成uint8类型
imshow(J)
title('平方根变换后的图像')
[X,map]=imread('forest.tif');
I=ind2gray(X,map);%把索引图像转换为灰度图像
imshow(I);
title('原图像');
improfile%用鼠标选择一条对角线,显示线段的灰度值
figure;subplot(121)
plot(0:0.01:1,sqrt(0:0.01:1))
axis square
title('平方根灰度变换函数')
subplot(122)
maxnum=double(max(max(I)));%取得二维数组最大值
J=sqrt(double(I)/maxnum);%把数据类型转换成double,然后进行平方根变换
%sqrt函数不支持uint8类型
J=uint8(J*maxnum);%把数据类型转换成uint8类型
imshow(J)
title('平方根变换后的图像')
3.直方图均衡化程序举例
% HISTGRAM EAQUALIZATION
clc;
% Clear command window
I=imread('tire.tif');
% reads the image in tire.tif into I
imshow(I);
% displays the intensity image I with 256 gray levels
clc;
% Clear command window
I=imread('tire.tif');
% reads the image in tire.tif into I
imshow(I);
% displays the intensity image I with 256 gray levels