Filter löschen
Filter löschen

Converting the outline of an image into a curved function

1 Ansicht (letzte 30 Tage)
은석 최
은석 최 am 18 Nov. 2021
Beantwortet: yanqi liu am 19 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.

Akzeptierte Antwort

yanqi liu
yanqi liu am 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);

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by