필터 지우기
필터 지우기

Converting the outline of an image into a curved function

조회 수: 1 (최근 30일)
은석 최
은석 최 2021년 11월 18일
답변: yanqi liu 2021년 11월 19일
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에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by