필터 지우기
필터 지우기

How can I convert the shape of one class to another using Matlab?

조회 수: 3 (최근 30일)
Gobert
Gobert 2021년 12월 14일
댓글: Gobert 2021년 12월 15일
Hi,
I have a situation that looks like this and I need your help.
I want to convert/modify the "shape of the edge outline" between the gray and white area (SEO-GWA) to the "shape of the edge outline" between the white and black area (SEO-WBA).
Does any one has a suggestion or solution to this problem?

채택된 답변

yanqi liu
yanqi liu 2021년 12월 15일
yes,sir,is the target to make inner gray inclose to outer white?
so,may be use the optimal method,such as
clc; clear all; close all;
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/834220/image.png');
bw = im2bw(img);
bw2 = im2bw(img, 0.9);
bw3 = logical(bw - bw2);
gray_info = mean2(img(bw3));
% change shape
for i = 1 : 20
bw4 = bwmorph(bw,'thin',i);
bw5 = bw3&bw4;
ins(i) = abs(length(find(bw5(:)))/length(find(bw3(:))) - 1);
end
[~,ind] = max(ins);
bw4 = bwmorph(bw,'thin',ind);
% set shape
img2 = zeros(size(img));
img2(bw) = 255;
img2(bw4) = gray_info;
figure; montage({mat2gray(img),mat2gray(img2)}, 'Size', [1 2], 'BackgroundColor', 'w', 'BorderSize', [2 2]);
now,we can find,left is origin,right is target,and inner right shape close to white
  댓글 수: 1
Gobert
Gobert 2021년 12월 15일
Thank you! Your code gives an idea on how to perfectly match the SEO-GWA with SEO-WBA.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

John D'Errico
John D'Errico 2021년 12월 14일
All you have is a picture, not a shape. Until you express those boundaries as a shape of some sort, you cannot do anything.
  1. Since both of them appear to be essentially convex obvjects, I might start by identifying pixels on the boundaries.
  2. Next, pick some point that lies in the "center" of both domains.
  3. Convert to polar coordinates, around that center. This will allow you to plor r(theta) for both curves.
  4. Smooth those relationships for r(theta). A simple scheme might be as a smoothing spline of some sort, though you would want it to have periodic end conditions. (My SLM toolbox would offer that constraint. You can download it for free from the File Exchange.) Alternatively, you can fit both expressions as essentially a Fourier series, just a sum of sin and cosine terms, of the form sin(n*theta) and cos(n*theta) for integer n. The superposed sum will be periodic, and continuously differentiable at theta = 0, 2*pi.
  5. Once you have the two relationships for r1(theta) and r2(theta), for any point on the first curve, you will simply scale it by the factor r2(theta)/r1(theta).
  6. Finally, convert back to cartesian coordinates.

Walter Roberson
Walter Roberson 2021년 12월 14일
If that boundary is close enough to be considered an ellipse, then there are File Exchange contributions to fit ellipses, and see also https://www.mathworks.com/matlabcentral/answers/584243-ellipse-fitting-with-matlab-using-fittype for some more methods.
The idea would be that you would fit an ellipse to the outer boundary and then use its orientation and eccentricty and foci to create an interior ellipse.
John's suggestions about fft and so on might be needed if you needed if the bumps in the outer edge are important features.
  댓글 수: 2
John D'Errico
John D'Errico 2021년 12월 14일
Yes. It depends on how much you need to chase the complete shape, how accurately you want to model it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by