Boundary Extraction Issue Using Image Restoration Techniques

3 visualizaciones (últimos 30 días)
Hi, I'm working on extracting boundary points from an image, but the output appears inverted. How can I correctly extract boundary points so the image restoration matches the original orientation? Here's my current MATLAB code:
clear all;
img = imread('parol.png'); % Replace with your image file
grayImg = rgb2gray(img); % Convert to grayscale
bwImg = imbinarize(grayImg); % Convert to binary image
% Invert the binary image if necessary
bwImg = imcomplement(bwImg);
% Fill holes in the binary image
bwImg = imfill(bwImg, 'holes');
% Get boundary points
boundaries = bwboundaries(bwImg);
% Extract the main boundary points
boundaryPoints = boundaries{1};
% Plot the boundary points
figure;
subplot(1,2,1)
imshow(img);
subplot(1,2,2)
plot(boundaryPoints(:,2), boundaryPoints(:,1), 'r', 'LineWidth', 2);
hold off;
daspect([1 1 1]);
Thanks!

Respuesta aceptada

Image Analyst
Image Analyst el 6 de Jul. de 2024
After you call plot, do this:
axis('on', 'image');
or you can do
axis ij
  6 comentarios
Yamina chbak
Yamina chbak el 9 de Jul. de 2024
Okay, I understand what you're trying to do, but I still find the image is inverted and clear on the y-axis; the numbers should go from bottom to top. Anyway, I will input an inverted image to make the output appear correct.
Thank you @Image Analyst for your help.
Image Analyst
Image Analyst el 9 de Jul. de 2024
Editada: Image Analyst el 14 de Jul. de 2024
Not sure what you're saying. Both the images have the same orientation, even though one is an image and one is a plot. Perhaps you're confused about the location of the origin for images and plots.
For images and arrays, the top row is row 0 and that is the origin, and the row numbers on the y axis increase as they go from the top left of the axes to the bottom left of the axes.
For plots, which have (x,y) plot coordinate points, the origin (0,0) point, is at the lower left, and the y axis tick labels on the y axis increase as they go from the bottom left of the axes to the top left of the axes.
That's just the convention everyone uses. MATLAB does give you functions to make it appear differently if you don't like the way the convention appears, and I've showed you some of those.
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by