MATLAB Answers

Dilate a viscircles? circle fitting

5 views (last 30 days)
mikel lasa
mikel lasa on 2 Nov 2020
Edited: mikel lasa on 12 Nov 2020
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);
%% filtro canny
F1= edge(img,'Canny',0.5,0.3);
imshowpair(img, F1, 'montage');
title(' Canny')
%% hough
[A,theta,rho] = hough (F1);
%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);
%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);
imshow(img), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
% 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;
%% 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);
%imshow(img), hold on


Sign in to comment.

Accepted Answer

mikel lasa
mikel lasa on 12 Nov 2020
Edited: mikel lasa on 12 Nov 2020
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.


Sign in to comment.




Community Treasure Hunt

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

Start Hunting!