Find the boundary of any edge in an image .

3 visualizaciones (últimos 30 días)
Atreyee Mondal
Atreyee Mondal el 3 de Nov. de 2019
Editada: Atreyee Mondal el 8 de En. de 2020
i need to find the edge of an image.
  3 comentarios
Image Analyst
Image Analyst el 3 de Nov. de 2019
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 el 12 de Dic. de 2019
(Answers Dev) Restored edit

Iniciar sesión para comentar.

Respuestas (1)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 3 de Nov. de 2019
Editada: Thiago Henrique Gomes Lobato el 3 de Nov. de 2019
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