Dilate a viscircles? circle fitting

5 次查看(过去 30 天)
Hello,
I have a binary imagen where I found 5 circles with imfindcircles and I plot them using viscircles. In order to do a least square fitting of that circle, I need to dilate this circles and get all edge pixels in a 2 pixel distance.
My problem is that I dont know how to dilate the circle that I get using viscircles, as this function only returns the center and radius of the circle. I know how to fit the circle, but, for that first I need to get those near pixels using a dilatation of the circle ploted by viscircles.
PD: Its a practice but our teacher told us to use dilatation to get those pixels and fit the circle.
This is my code
clc;clear;close all;
impath = 'metal-parts-01.png';
img = imread(impath);
%figure();
%imshow(img);
%figure();
%imhist(img);
%% filtro canny
F1= edge(img,'Canny',0.5,0.3);
figure();
imshowpair(img, F1, 'montage');
title(' Canny')
%% hough
[A,theta,rho] = hough (F1);
%figure();
%imshow(imadjust(rescale(A)),'XData',theta,'YData',rho, 'InitialMagnification','fit')
%title(' transformada de hough')
%xlabel('\theta'), ylabel('\rho'); axis on, axis normal, hold on; colormap(gca,hot);
%% picos
peaks = houghpeaks(A,5,'Threshold',5);
%figure();
%imshow(A,[],'XData',theta,'YData',rho,'InitialMagnification','fit');
%title(' picos hough')
%xlabel('\theta'), ylabel('\rho'); axis on, axis normal, hold on; plot(theta(peaks(:,2)),rho(peaks(:,1)),'s','color','white');
%% lineas
lines = houghlines (F1,theta,rho,peaks);
figure()
imshow(img), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment len = norm(lines(k).point1 - lines(k).point2); if ( len > max_len) max_len = len; xy_long = xy;
end
%% circulos
LowD = 6; LowL =25;
HighD =25; HighL = 80;
[centersL,radiiL]=imfindcircles(img,[LowL HighL],'ObjectPolarity','bright','Sensitivity',0.95);
[centersD,radiiD]=imfindcircles(img,[LowD HighD],'ObjectPolarity','dark','Sensitivity',0.90);
%figure()
%imshow(img), hold on
viscircles(centersD,radiiD);
viscircles(centersL,radiiL);

采纳的回答

mikel lasa
mikel lasa 2020-11-12
编辑:mikel lasa 2020-11-12
Thank for the answer,
I solved the problem, I have created a zero matrix with my original edge image size and the input a circle with the command insert shape. Then I have converted to gray with rgb2gray.
After that, I made the dilate using this matrix.

更多回答(1 个)

Manas Meena
Manas Meena 2020-11-12

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by