資源簡介
在matlab中尋找圓形的特征并直接提取,2012年實現的,重新編輯了內容,具體算大是 改進后的霍夫曼算法,改進點有3處,個人認為還可以繼續改進。有想交流的可以留言。
代碼片段和文件信息
%提取圖像中的圓形特征
%%?Identifying?Round?objects
%?Your?goal?is?to?classify?objects?based?on?their?roundness?using
%?|bwboundaries|?a?boundary?tracing?routine.
%
%?Copyright?1993-2005?The?MathWorks?Inc.?
%?$Revision:?1.1.6.3?$??$Date:?2005/12/12?23:21:52?$
%
%%?Step?1:?Read?Image
%?Read?in?|pills_etc.png|.
RGB?=?imread(‘test.bmp‘);
imshow(RGB);
hold?on
%%?Step?2:?Threshold?the?Image
%?Convert?the?image?to?black?and?white?in?order?to?prepare?for
%?boundary?tracing?using?|bwboundaries|.
I?=?rgb2gray(RGB);
threshold?=?graythresh(I);
bw?=?im2bw(Ithreshold);
figure;
imshow(bw)
%%?Step?3:?Remove?the?Noise
%?Using?morphology?functions?remove?pixels?which?do?not?belong?to?the
%?objects?of?interest.
%?remove?all?object?containing?fewer?than?30?pixels
bw?=?bwareaopen(bw10);
%?fill?a?gap?in?the?pen‘s?cap
se?=?strel(‘disk‘2);
figure;
bw?=?imclose(bwse);
%?fill?any?holes?so?that?regionprops?can?be?used?to?estimate
%?the?area?enclosed?by?each?of?the?boundaries
bw?=?imfill(bw‘holes‘);
imshow(bw)
%%?Step?4:?Find?the?Boundaries
%?Concentrate?only?on?the?exterior?boundaries.??Option?‘noholes‘?will
%?accelerate?the?processing?by?preventing?|bwboundaries|?from?searching?
%?for?inner?contours.
[BL]?=?bwboundaries(bw‘noholes‘);
%?Display?the?label?matrix?and?draw?each?boundary
figure;
imshow(label2rgb(L?@jet?[.5?.5?.5]))
hold?on
figure;
for?k?=?1:length(B)
??boundary?=?B{k};
??plot(boundary(:2)?boundary(:1)?‘w‘?‘LineWidth‘?2)
end
%%?Step?5:?Determine?which?objects?are?Round
%?Estimate?each?
評論
共有 條評論