Converting the outline of an image into a curved function

5 次查看(过去 30 天)
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.

采纳的回答

yanqi liu
yanqi liu 2021-11-19
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by