save coordinates by using impoly..
이전 댓글 표시
Hi, I am using imrect to select what I need from image and save the coordinates and then show the image with that coordinates see the code
I = imread('gantrycrane.png');
imshow(I);
s = imrect;
P = getPosition(s)
x=P(1,1);
y=P(1,2);
w=P(1,3);
h=P(1,4);
II = I(y:y+h,x:x+w);
imshow(II);
now I want to use impoly to do same thing like what I did with imrect I want to select what I need by using impoly and save the coordinates and show the image with that coordinates ... I wish my question is clear ...
채택된 답변
추가 답변 (1개)
Guillaume
2017년 5월 9일
Well, you can't crop an image to an arbitrary polygon since an image must be rectangular. Guessing, maybe you want the image crop to the bounding box of the polygon, with all pixels outside the polygon set to black:
sourceimage = imread('gantrycrane.png');
imshow(sourceimage);
hpoly = impoly;
polypoints = hpoly.getPosition;
croppedimage = sourceimage;
croppedimage(~repmat(hpoly.createMask, 1, 1, 3)) = 0; %set outside of polygon to black
croppedimage = croppedimage(min(polypoints(:, 2)):max(polypoints(:, 2)), min(polypoints(:, 1)):max(polypoints(:, 1)), :);
imshow(croppedimage)
댓글 수: 8
Khaled Al-Faleh
2017년 5월 11일
Guillaume
2017년 5월 12일
Well, considering you haven't told us what it is you want in enough detail, I'd say my answer does what you want.
If not, please explain what it is you want exactly. Preferably by showing examples.
Khaled Al-Faleh
2017년 5월 12일
What do you think
min(polypoints(:, 2)):max(polypoints(:, 2))
min(polypoints(:, 1)):max(polypoints(:, 1))
is in the line that performs the crop, if not the bounds of the cropped image?
Khaled Al-Faleh
2017년 5월 12일
Khaled Al-Faleh
2017년 5월 12일
Image Analyst
2017년 5월 12일
편집: Image Analyst
2017년 5월 12일
Why do you think images are indexed (x,y), they ARE NOT! Images take row and column as the indexes in that order, so you need to put y first, NOT x
II = sourceimage(y:y+h,x:x+w);
Also, your equations for x, y, w, and h are wrong.
Khaled Al-Faleh
2017년 5월 12일
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
