Boundary Extraction Issue Using Image Restoration Techniques
3 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Image Analyst
2024-7-6
After you call plot, do this:
axis('on', 'image');
or you can do
axis ij
6 个评论
Image Analyst
2024-7-9
编辑:Image Analyst
2024-7-14
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!