Info

This question is closed. Reopen it to edit or answer.

How to smoothen a curve so I can separate 2 objects?

1 view (last 30 days)
Eric
Eric on 24 Feb 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
Greetings to all.
I wish to smoothen a curve drawn in an image, so I can separate it into 2 objects.
Here is the code used to produce the curve:
THETA=linspace(0,pi,cirP);
Radii = abs( drawPoint(1,2) - cenDraw(1,2) );
[cirCoorX cirCoorY] = pol2cart(THETA,Radii);
cirCoorY = cirCoorY + cenDraw(1,1);
cirCoorX = cirCoorX + cenDraw(1,2);
cirCoor = zeros( cirP, 2 );
cirCoor(:,1) = cirCoorY;
cirCoor(:,2) = cirCoorX;
% round up the decimal to integer
cirCoor2 = cirCoor;
for i = 1 : cirP
yCoor = cirCoor2(i,1);
xCoor = cirCoor2(i,2);
yCoorUp = ceil(yCoor);
xCoorUp = ceil(xCoor);
if yCoorUp ~= yCoor
yDiff = yCoorUp - yCoor;
if yDiff >= 0.5
yCoor = ceil(yCoor);
else
yCoor = floor(yCoor);
end
end
if xCoorUp ~= xCoor
xDiff = xCoorUp - xCoor;
if xDiff >= 0.5
xCoor = ceil(xCoor);
else
xCoor = floor(xCoor);
end
end
cirCoor2(i,1) = yCoor;
cirCoor2(i,2) = xCoor;
end
%%Draw the arc
bwFil2 = bwFil;
for i = 1 : cirP
yBlack = cirCoor2(i,1);
xBlack = cirCoor2(i,2);
bwFil2(yBlack,xBlack) = 0;
% figure; imshow(bwFil2); title('bwFil2')
end
Here is the image before the curve is drawn: http://www.imgplace.com/viewimg543/1755/94beforecurve.png
As you can notice, the curve is not smooth and the bwlabel may not be able to recognise 2 separate objects properly.
Any guide is welcomed! Thanks.

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!