How to get and plot boundary/vertex of drawn polygon
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to use drawpolygon to trace an imported image and then plot the boundary in a normal figure elsewhere. Matlab seems to take the position in terms of pixels from the top left corner of the image, rather than x,y coordinates. Is there a way to convert the pixel coordinates to x,y or a way to get the x,y coordinates of the drawn boundary?
h = drawpolygon('FaceAlpha',0);
h.Position
0 Commenti
Risposte (1)
Amish
il 15 Set 2023
Hi Michael,
I see that you are having issue with the Coordinates while using the ‘drawpolygon’ method where the coordinates are used considering the distances from the top-left corner while you desire it to be the XY coordinates.
The actual problem in this case is that it is essential for you to understand the coordinate system used. In MATLAB, images are typically represented using pixel coordinates, with the origin (0,0) located at the top-left corner of the image. If you want to convert pixel coordinates to the (x, y) coordinate system, you'll need to consider the scaling factor and the image size.
Here is a generic code that might help you to convert the pixel coordinates to (x, y) coordinates:
% Get the Image Size
[imageHeight, imageWidth, ~] = size(yourImage); % Replace 'yourImage' with your image variable
% Convert Pixel Coordinates to (x,y) Coordinates
x = (pixelX / imageWidth) * imageXRange;
y = (pixelY / imageHeight) * imageYRange;
% Now proceed with your workflow
h = drawpolygon('FaceAlpha',0);
h.Position
You can also refer to the official documentation and example here: https://www.mathworks.com/help/images/ref/drawpolygon.html
Hope this helps.
Regards
Amish
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!