Effacer les filtres
Effacer les filtres

Converting the outline of an image into a curved function

1 vue (au cours des 30 derniers jours)
은석 최
은석 최 le 18 Nov 2021
I want to convert the contour (or skeleton) on the binary image into a curve (or function).
The reason is that tangent and normal lines are required at each part of the curve.
The image below explains the content of the question.
I need your help.
Thank you.

Réponse acceptée

yanqi liu
yanqi liu le 19 Nov 2021
clc;clear all;close all;
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/805454/image.jpeg');
% segment
bw = imbinarize(rgb2gray(img));
bt = bw;
bw = ~bw;
bw = imclose(bw, strel('square', 5));
c = repmat(round(size(bw,2)*0.3), size(bw,1), 1);
r = 1:size(bw,1);
bw2 = bwselect(bw, c, r);
bw2 = imerode(bw2, strel('square', 5));
[L,~] = bwlabel(bw2);
stats = regionprops(L);
rect1 = round(stats(1).BoundingBox);
rect2 = round(stats(2).BoundingBox);
bw1 = imcrop(bt, rect1); bw1 = imclose(bw1, strel('line', 11, 90));
bw2 = imcrop(bt, rect2); bw2 = imclose(bw2, strel('line', 11, 90));
% curve fit
[y,x] = find(bw2);
[y,ind] = sort(y);
[y,ia,ic] = unique(y);
x = x(ia);
[fitobject,~,~] = fit(y,x,'smoothingspline');
figure; imshow(bw2, []);
x2 = fitobject(y);
hold on; plot(x2, y,'r-','LineWidth',2);

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by