MATLAB用數學形態學法提取影像邊界
- 方法一
- 方法二
方法一
主要函式:
graythresh() ; im2bw() ; bwperim() ;
代碼如下
img=imread('ball.jpg'); %原影像為灰度圖
subplot(1,2,1);
imshow(img);
title('原影像');
threshold= graythresh(img); %使用最大類間方差法找到圖片的一個合適的閾值(threshold=0.4745)
img_1=im2bw(img,threshold); %用這個閾值把灰度影像轉換為二值影像(像素值>0.4745*255的變為255白,其他的變為0黑)
img_2=bwperim(img_1); %用bwperim函式查找二值影像的邊緣
subplot(1,2,2);
imshow(img_2);
title('邊緣提取后的影像')
運行結果

方法二
主要函式:
entropyfilt() ; bwareaopen() ; rangefilt() ;
代碼如下
img=imread('ball.jpg');
subplot(2,3,1);
imshow(img);
title('原影像');
img_1 = entropyfilt(img); %創建紋理影像
img_2 = mat2gray(img_1); %轉化為灰度影像
subplot(2,3,2)
imshow(img_2);
title('紋理影像');
img_3 = im2bw(img_2,0.7); %轉化為二值影像
subplot(2,3,3);
imshow(img_3);
title('二值影像');
img_4 = bwareaopen((1-img_3),3000,8); %提取大小球區域紋理
subplot(2,3,4);
imshow(img_4);
title('不同區域紋理影像');
img_5= rangefilt (img,ones(7)); %rangefilt濾波
subplot(2,3,5);
imshow(img_5);
title('濾波后影像');
運行結果

對函式理解還不夠深刻,如有錯誤望指正!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/357221.html
標籤:其他
上一篇:YOLOV3訓練環境的搭建
