数字图像处理(一):灰度变换和直方图处理
生活随笔
收集整理的這篇文章主要介紹了
数字图像处理(一):灰度变换和直方图处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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:heightfor j = 1: widthNumPixel(I(i,j) + 1) = NumPixel(I(i,j) + 1) + 1;%對應灰度值像素點數量增加一end end %計算灰度分布密度 ProbPixel = zeros(1,256); for i = 1:256ProbPixel(i) = NumPixel(i) / (height * width * 1.0); end %計算累計直方圖分布 CumuPixel = zeros(1,256); for i = 1:256if i == 1CumuPixel(i) = ProbPixel(i);elseCumuPixel(i) = CumuPixel(i - 1) + ProbPixel(i);end end %累計分布取整 CumuPixel = uint8(255 .* CumuPixel +0.5); %對灰度值進行映射(均衡化) for i = 1:heightfor j = 1: widthI(i,j) = CumuPixel(I(i,j)+1);end endsubplot(223) imshow(I)%顯示均衡化后圖像 subplot(224) imhist(I)%顯示均衡化后圖像直方圖 ylim('auto') xlim('auto')?
轉載于:https://www.cnblogs.com/pursuit1996/p/4852581.html
總結
以上是生活随笔為你收集整理的数字图像处理(一):灰度变换和直方图处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于pipelineDB调用GetLoc
- 下一篇: 数据挖掘-贝叶斯定理