资源简介
在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
评论
共有 条评论