save coordinates by using impoly..
Ältere Kommentare anzeigen
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 ...
Akzeptierte Antwort
Weitere Antworten (1)
Guillaume
am 9 Mai 2017
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 Kommentare
Khaled Al-Faleh
am 11 Mai 2017
Guillaume
am 12 Mai 2017
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
am 12 Mai 2017
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
am 12 Mai 2017
Khaled Al-Faleh
am 12 Mai 2017
Image Analyst
am 12 Mai 2017
Bearbeitet: Image Analyst
am 12 Mai 2017
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
am 12 Mai 2017
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
