利用edge()函數提取圖像輪廓,繪製出對象的邊界和提取邊界座標信息,matlab實現代碼以下:app
close all;clear all;clc; % 提取圖像輪廓,提取圖像邊緣 I = imread('yifu.jpg'); c = im2bw(I,graythresh(I)); figure; subplot(131);imshow(I); c = flipud(c); %實現矩陣c上下翻轉 b = edge(c,'canny'); [u,v] = find(b); %返回邊界矩陣b中非零元素的位置 xp = v; %行值v賦給xp yp = u; %列值u賦給yp x0 = mean([min(xp),max(xp)]); %x0爲行值的均值 y0 = mean([min(yp),max(yp)]); %y0爲列值得均值 xp1 = xp-x0; yp1 = yp-y0; [cita,r] = cart2pol(xp1,yp1); q = sortrows([cita,r]); %從r列開始比較數值並按升序排序 cita = q(:,1); %賦角度值 r = q(:,2); %賦半徑模值 subplot(132);polar(cita,r); %畫極座標下的輪廓圖 [x,y] = pol2cart(cita,r); x = x+x0; y = y+y0; subplot(133);plot(x,y);axis equal;
![點擊並拖拽以移動](http://static.javashuo.com/static/loading.gif)
程序運行結果:函數
![點擊並拖拽以移動](http://static.javashuo.com/static/loading.gif)