Find the boundary of any edge in an image .

조회 수: 1 (최근 30일)
Atreyee Mondal
Atreyee Mondal 2019년 11월 3일
편집: Atreyee Mondal 2020년 1월 8일
i need to find the edge of an image.
  댓글 수: 3
Image Analyst
Image Analyst 2019년 11월 3일
No it's not. You deleted everything. Please respect Thiago's time to answer you, and put back the question and data.
Rena Berman
Rena Berman 2019년 12월 12일
(Answers Dev) Restored edit

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

답변 (1개)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2019년 11월 3일
편집: Thiago Henrique Gomes Lobato 2019년 11월 3일
Your input is just the image, so I can't check the solution in your exact data, but this should either way solve your problem or at least guide you to a solution, I tried to let the code as commented as possible for you to be able to follow it:
% Here I generate a contour data, which you already have
t = 0:0.001:1;
x = cos(2*pi*t);
y = 2*sin(2*pi*t);
Angle = 2*pi*t*180/pi;
DistanceFromCenter = sqrt(x.^2+y.^2);
% From here on is the reconstruction process
% Get back x and y contour coordinates
xValues = DistanceFromCenter.*cos(Angle/180*pi);
yValues = DistanceFromCenter.*sin(Angle/180*pi);
% Create Image Template
SizeImg = 400;
Img = zeros(SizeImg);
% Map numerical x-y Values to an index
xMapped = xValues-min(xValues)+1; %% Shift image to minimum 1 so index is never 0
yMapped = yValues-min(yValues)+1;
NormFactor = max(max(abs(xMapped),max(abs(yMapped))));
xMapped = round(xMapped/NormFactor*SizeImg); % Scale to maximum
yMapped = round(yMapped/NormFactor*SizeImg);
% Create Binary Contourn substituing the discrete boundary points for 1
for idx=1:length(xMapped)
Img(yMapped(idx),xMapped(idx)) = 1;
end
% If you want the image filled, fill the holes (This will only work if you
% have enough angle information, otherwise the contour will have too many holes for
% a reconstruction)
ImgFilled = imfill(Img==1,'holes'); % Img==1 is to transform the image in a binary
% Plots
figure
% Real Contour
subplot(1,4,1)
plot(xValues,yValues)
title('Real Contour')
axis square
% Discrete Contour
subplot(1,4,2)
plot(xMapped,yMapped)
title('Discrete Reconstructed Contour')
axis square
% Generate Image Contour
subplot(1,4,3)
imshow(Img)
title('Image Contour')
% Filled Image
subplot(1,4,4)
imshow(ImgFilled)
title('Filled Image Contour')

Community Treasure Hunt

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

Start Hunting!

Translated by