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!
