1秒登錄
利用edge()函數提取圖像輪廓,繪制出對象的邊界和提取邊界坐標信息,matlab實現代碼如下:
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;
程序運行結果:
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。