1.利用对数变换减小动态范围
f = imread('E:\【数字图像处理】\Images\DIP3E_Original_Images_CH03\Fig0305(a)(DFT_no_log).tif'); g = im2uint8(mat2gray(log(1+double(f)))); imshow(g);
2.负片处理两种方式
g = imadjust(f,[0 1],[1 0]);%负片处理
g = imcomplement(f);%负片处理
3.突出感兴趣的灰度区
g = imadjust(f,[0.5 0.75],[0 1]);
4.改变gamma的值来增强图像
g = imadjust(f,[ ],[ ],2);
*gamma>1时调暗,gamma<1时调亮
5.对比度拉伸
g = imadjust(f,stretchlim(f),[1 0]);
6.利用intrans实现对比度拉伸
g = intrans(f,'stretch',mean2(tofloat(f)),0.9);
7.绘制图像的直方图
p = imhist(f)/numel(f);%归一化
imhist(p)
8.直方图均衡:扩展了图像的动态范围,提高对比度
f = imread('E:\【数字图像处理】\Images\DIP3E_Original_Images_CH03\Fig0310(b)(washed_out_pollen_image).tif');%读入图像 imshow(f);%显示图像 figure(2); imhist(f);%绘制直方图 ylim('auto');%自动设置y轴上下限范围 g=histeq(f,256);%直方图均衡,256为设定的灰度级数,不设的话默认为64 figure(3) imshow(g); figure(4) imhist(g); ylim('auto');
%直方图均衡化 I = imread('E:\【数字图像处理】\Images\DIP3E_Original_Images_CH03\Fig0310(b)(washed_out_pollen_image).tif'); [height,width] = size(I); figure subplot(221) imshow(I)%显示原始图像 subplot(222) imhist(I)%显示原始图像直方图 ylim('auto'); %进行像素灰度统计; NumPixel = zeros(1,256);%统计各灰度数目,共256个灰度级 for i = 1:height for j = 1: width NumPixel(I(i,j) + 1) = NumPixel(I(i,j) + 1) + 1;%对应灰度值像素点数量增加一 end end %计算灰度分布密度 ProbPixel = zeros(1,256); for i = 1:256 ProbPixel(i) = NumPixel(i) / (height * width * 1.0); end %计算累计直方图分布 CumuPixel = zeros(1,256); for i = 1:256 if i == 1 CumuPixel(i) = ProbPixel(i); else CumuPixel(i) = CumuPixel(i - 1) + ProbPixel(i); end end %累计分布取整 CumuPixel = uint8(255 .* CumuPixel +0.5); %对灰度值进行映射(均衡化) for i = 1:height for j = 1: width I(i,j) = CumuPixel(I(i,j)+1); end end subplot(223) imshow(I)%显示均衡化后图像 subplot(224) imhist(I)%显示均衡化后图像直方图 ylim('auto') xlim('auto')