Boundary Extraction Issue Using Image Restoration Techniques
조회 수: 2 (최근 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]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1728941/image.png)
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!