一文詳解matlab實(shí)現(xiàn)形態(tài)學(xué)圖像處理
目的
文章和代碼以及樣例圖片等相關(guān)資源,已經(jīng)歸檔至【Github倉庫:digital-image-processing-matlab】
- 膨脹的簡單應(yīng)用、使用 strel 函數(shù)、腐蝕的說明
- 函數(shù)imopen 和imclose 的應(yīng)用、使用IPT函數(shù)bwhitmiss
- 灰度圖像形態(tài)學(xué)開運(yùn)算和閉運(yùn)算
- 灰度圖像形態(tài)學(xué)使用重構(gòu)刪除復(fù)雜圖像的背景
內(nèi)容
膨脹的簡單應(yīng)用
A=imread('D:\pic\DIP3E_CH04\Fig0419(a)(text_gaps_of_1_and_2_pixels).tif');
figure, imshow(A)
B=[0 1 0;1 1 1;0 1 0];
A2=imdilate(A,B);
figure,imshow(A2)
使用 strel 函數(shù)分解結(jié)構(gòu)元素的說明
se=strel('diamond',5)
decomp=getsequence(se);
whos
decomp(1)
decomp(2)
decomp(3)
decomp(4)
腐蝕的說明
A=imread('D:\pic\DIP3E_CH09\Fig0905(a)(wirebond-mask).tif');
figure, imshow(A)%原圖像
se=strel('disk',10)
A2=imerode(A,se)
figure, imshow(A2)%半徑為10 的圓盤腐蝕后的圖像
se=strel('disk',5)
A3=imerode(A,se)
figure, imshow(A3)%半徑為5 的圓盤腐蝕后的圖像
A4=imerode(A,strel('disk',20))
figure, imshow(A4)%半徑為20 的圓盤腐蝕后的圖像
函數(shù)imopen 和imclose 的應(yīng)用
f=imread('D:\pic\DIP3E_CH09\Fig0905(a)(wirebond-mask).tif');
figure, imshow(f)%原圖像
se=strel('square',20);
fo=imopen(f,se);
figure, imshow(fo)%開運(yùn)算后的圖像
fc=imclose(f,se);
figure, imshow(fc)%閉運(yùn)算后的圖像
foc=imclose(fo,se);
figure, imshow(foc)%圖像A2 經(jīng)閉運(yùn)算后的圖像
使用 IPT 函數(shù)bwhitmiss
f=imread('D:\pic\DIP3E_CH09\FigP0918(left).tif')
figure,imshow(f)
B1=strel([0 0 0;0 1 1;0 1 0]);
B2=strel([1 1 1;1 0 0;1 0 0]);
g=bwhitmiss(f,B1,B2);
figure,imshow(g)
灰度圖像形態(tài)學(xué)開運(yùn)算和閉運(yùn)算
%%%%%%%%%使用開運(yùn)算和閉運(yùn)算做形態(tài)學(xué)平滑%%%%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0941(a)(wood_dowels).tif');
figure, imshow(f)%原圖像
se=strel('disk',5);
fo=imopen(f,se);
figure, imshow(fo)%開運(yùn)算后的圖像
foc=imclose(fo,se);
figure, imshow(foc)%圖像A2 經(jīng)閉運(yùn)算后的圖像
fasf=f;
for k=2:5
se=strel('disk',k);
fasf=imclose(imopen(fasf,se),se);
end
figure,imshow(fasf) %%%%%% 交替順序?yàn)V波后的圖像
%%%%%%%%%%使用頂帽變換%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
figure, imshow(f)%原圖像
se=strel('disk',10);
fo=imopen(f,se);
figure, imshow(fo)%經(jīng)開運(yùn)算處理后的圖像
f2=imsubtract(f,fo);
figure, imshow(f2)
f2=imtophat(f,se);
figure, imshow(f2)
se=strel('disk',3);
g=imsubtract(imadd(f,imtophat(f,se)),imbothat(f,se));%低帽、頂帽
figure, imshow(g)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%顆粒分析%%%%%%%%%%%%%%
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0940(a)(rice_image_with_intensity_gradient).tif');
sumpixels=zeros(1,36);
for k=0:35
se=strel('disk',k);
fo=imopen(f,se);
sumpixels(k+1)=sum(fo(:));
end
figure,plot(0:35,sumpixels);
xlabel('k');
ylabel('surface area')
figure, plot(-diff(sumpixels))
xlabel('k');
ylabel('surface area reduction')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
灰度圖像形態(tài)學(xué)使用重構(gòu)刪除復(fù)雜圖像的背景
%灰度圖像形態(tài)學(xué)使用重構(gòu)刪除復(fù)雜圖像的背景
clear all
clc
f=imread('D:\pic\DIP3E_CH09\Fig0944(a)(calculator).tif');
figure, imshow(f)%原圖像
f_obr=imreconstruct(imerode(f,ones(1,71)),f);
figure, imshow(f_obr)
f_o=imopen(f,ones(1,71));%for comparison
figure, imshow(f_o)
f_thr=imsubtract(f,f_obr);
figure, imshow(f_thr)
f_th=imsubtract(f,f_o);%or imtophat(f,ones(1,71))
figure, imshow(f_th)
g_obr=imreconstruct(imerode(f_thr,ones(1,11)),f_thr);
figure, imshow(g_obr)
g_obrd=imdilate(g_obr,ones(1,21));
figure, imshow(g_obrd)
f2=imreconstruct(min(g_obrd,f_thr),f_thr);
figure, imshow(f2)
參考文獻(xiàn):
[2] 阮秋琦. 數(shù)字圖像處理(MATLAB版)[M]. 北京:電子工業(yè)出版社, 2014.
[3] 岡薩雷斯. 數(shù)字圖像處理(第三版)[M]. 北京:電子工業(yè)出版社, 2011.
以上就是一文詳解matlab實(shí)現(xiàn)形態(tài)學(xué)圖像處理的詳細(xì)內(nèi)容,更多關(guān)于matlab形態(tài)學(xué)圖像處理的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
c++?error:crosses?initialization?of問題解決分析
這篇文章主要介紹了c++?error:crosses?initialization?ofde?問題解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
詳解設(shè)計(jì)模式中的中介者模式在C++編程中的運(yùn)用
這篇文章主要介紹了設(shè)計(jì)模式中的中介者模式在C++編程中的運(yùn)用,中介者模式將對(duì)象間的通信封裝到一個(gè)類中,將多對(duì)多的通信轉(zhuǎn)化為一對(duì)多的通信,降低了系統(tǒng)的復(fù)雜性,需要的朋友可以參考下2016-03-03

