matlab数字图像处理函数,MATLAB数字图像处理学习(二)|常用函数
以下的學習整理來自《數字圖像處理原理與實踐(MATLAB版)》
im2bw
功能:將索引圖象、灰度圖像和RGB彩色圖像轉換為二值圖像 調用形式: >BW = im2bw(I,level) BW = im2bw(X,cmap,level) BW = im2bw(RGB,level)
其中level用于設置閾值。level取值范圍[0, 1]。 示例:
edge
功能:功能是采用I作為它的輸入,并返回一個與I相同大小的二值化圖像BW,在函數檢測到邊緣的地方為1,其他地方為0。采用灰度或一個二值化圖像I作為它的輸入,并返回一個與I相同大小的二值化圖像BW,在函數檢測到邊緣的地方為1,其他地方為0。
調用形式: >BW = edge(I) BW = edge(I,method) BW = edge(I,'sobel')%自動選擇閾值用Sobel算子進行邊緣檢測。 BW = edge(I,method,threshold) BW = edge(I,method,threshold,direction) BW = edge(---,'nothinning') BW = edge(I,method,threshold,sigma) BW = edge(I,method,threshold,h) [BW,threshOut] = edge(---) [BW,threshOut,Gv,Gh] = edge(---)
示例: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23clear;
% 使用imread()函數讀取圖像
I1=imread('C:\Users\huayang\Desktop\MATLAB photo\測試.png');
I=im2bw(I1);
% 將索引彩色圖象轉換為灰度圖像
bw1=edge(I,'roberts');
bw2=edge(I,'sobel');
bw3=edge(I,'prewitt');
bw4=edge(I,'log');
bw5=edge(I,'canny',[0.032,0.08],1);
figure
subplot(2,3,1),imshow(I);
title('原始圖像');
subplot(2,3,2),imshow(bw1);
title('roberts');
subplot(2,3,3),imshow(bw2);
title('sobel');
subplot(2,3,4),imshow(bw3);
title('prewitt');
subplot(2,3,5),imshow(bw4);
title('log');
subplot(2,3,6),imshow(bw5);
title('canny');
strel
功能:構造結構元素(Structuring element)。所謂結構元素,可以看做是一張小圖像,它通常用于圖像的形態學運算(如膨脹、腐蝕、開運算、閉運算)。 調用形式: >SE = strel(shape, parameters)%根據shape指定的類型創建一個結構元素SE。 SE = strel('ball', R, H, N) SE = strel('diamond', R) SE = strel('disk', R, N) SE = strel('line', LEN, DEG) SE = strel('octagon', R) SE = strel('pair', OFFSET) SE = strel('periodicline', P, V) SE = strel('rectangle', MN) SE = strel('square', W)
示例: 見下一例。
imdilate與imerode
功能:可以使用imdilate函數進行圖像膨脹;可以使用imerode函數進行圖像腐蝕。 調用形式: >J = imdilate(I,SE) J = imdilate(I,nhood) J = imdilate(---,packopt) J = imdilate(---,shape) J = imerode(I,SE) J = imerode(I,nhood) J = imerode(---,packopt,m) J = imerode(---,shape)
示例: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15clear;
% 使用imread()函數讀取圖像
I1=imread('C:\Users\huayang\Desktop\MATLAB photo\測試.png');
I=im2bw(I1);
sel1=strel('disk',2);%創建一個指定半徑1的平面圓盤形的結構元素
im1=imdilate(I,sel1);
im2=imerode(I,sel1);
subplot(2,2,1),imshow(I1);
title('彩色圖像');
subplot(2,2,2),imshow(I);
title('原始圖像');
subplot(2,2,3),imshow(im1);
title('圖像膨脹');
subplot(2,2,4),imshow(im2);
title('圖像腐蝕');
imfill
功能:該函數用于填充圖像區域和“空洞”。 調用形式: >BW2 = imfill(BW) 這種格式將一張二值圖像顯示在屏幕上, 允許用戶使用鼠標在圖像上點幾個點, 這幾個點圍成的區域即要填充的區域。要以這種交互方式操作, BW必須是一個二維的圖像。用戶可以通過按Backspace鍵或者Delete鍵來取消之前選擇的區域;通過shift+鼠標左鍵單擊或者鼠標右鍵單擊或雙擊可以確定選擇區域。 [BW2,locations] = imfill(BW) 這種方式, 將返回用戶的取樣點索引值。注意這里索引值不是選取樣點的坐標。 BW2 = imfill(BW,locations) 這種格式允許用戶編程時指定選取樣點的索引。locations是個多維數組時, 數組每一行指定一個區域。 BW2 = imfill(BW,'holes') 填充二值圖像中的空洞區域。 如, 黑色的背景上有個白色的圓圈。 則這個圓圈內區域將被填充。 I2 = imfill(I) 這種調用格式將填充灰度圖像中所有的空洞區域。
示例: 1
2
3
4
5
6
7
8
9clear;
% 使用imread()函數讀取圖像
I1=imread('C:\Users\huayang\Desktop\MATLAB photo\測試.png');
I=im2bw(I1);
im3=imfill(I,'hole');
subplot(1,2,1),imshow(I);
title('原始圖像');
subplot(1,2,2),imshow(im3);
title('圖像填充');
bwareaopen
功能:刪除二值圖像BW中小面積對象,默認情況下使用8鄰域。 調用形式: >BW2 = bwareaopen(BW,P) BW2 = bwareaopen(BW,P,conn)
示例: 1
2
3
4
5
6
7
8
9clear;
% 使用imread()函數讀取圖像
I1=imread('C:\Users\huayang\Desktop\MATLAB photo\測試.png');
I=im2bw(I1);
im1=bwareaopen(I,1200);
subplot(1,2,1),imshow(I);
title('原始圖像');
subplot(1,2,2),imshow(im1);
title('刪除對象');
關于matlab函數_連通區域得詳解,可參考matlab函數bwareaopen的詳解 關于matlab圖像處理的更多知識,可參考形態學圖像處理 最后,再奉上一個表情包用于測試:
23333
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的matlab数字图像处理函数,MATLAB数字图像处理学习(二)|常用函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 毕业就业推荐表计算机,毕业生就业推荐表
- 下一篇: html自动图片尺寸,关于html:CS