資源簡介
matlab的面積計(jì)算實(shí)例。通過對于圖像的預(yù)處理包括二值化,灰度化,膨脹腐蝕,平滑處理等手段,得到一個(gè)比較完整的閉合圖形,然后通過bwarea函數(shù)進(jìn)行面積計(jì)算
代碼片段和文件信息
close?all;clear?all;clc;
I=imread(‘C:\Users\wuzhi\Desktop\2.jpg‘);
figure
imshow(I);
I2=rgb2gray(I);
[junkthreshold]=edge(I2‘sobel‘);
fudgeFactor=.5;
BWs=edge(I2‘sobel‘threshold*fudgeFactor);
figure;
subplot(221)imshow(BWs)title(‘邊緣梯度二值膜‘);
se90=strel(‘line‘390);
se0=strel(‘line‘30);
BWsdil=imdilate(BWs[se90?se0]);
subplot(222);
imshow(BWsdil)title(‘膨脹梯度掩膜‘);
BWdfill=imfill(BWsdil‘holes‘);
subplot(223);
imshow(BWdfill)title(‘填充空洞后的二值圖像‘);
BWnobord=imclearborder(BWdfill4);
subplot(224);imshow(BWnobord)title(‘清除邊緣的二值圖像‘);
SeD=strel(‘diamond‘1);
BWfinal=imerode(BWnobordSeD);
BWfin
評論
共有 條評論