Trying to rotate a shape made with drawpolygon

Technical Source
2 min readApr 10, 2023

--

I need to analyze particaulr section of an image for what colors they are and found “drawfreehand” and “drawpolygon” to not have the level of precision I’m looking for in a mask, due to the space for human error.

I want to throw a shape of the correct dimensions onto the image and have the user drag it to the right location, which includes translation and rotation motion. I got it figured out with drawRectangle and then went ahead and drew up my shape so I could use drawPolygon to create my shape. Unfortunatley, I found that rotation isn’t a feature in drawPolygon! Is there any other way to allow a user to dynamically rotate a figure drawn using drawPolygon? The data is already recorded and, as there are hundreds of images, it’s not feasible to manually straighten them.

Using drawRectangle, this line of code worked very well for me:

h = drawrectangle('Position',[50,50,14,57],'Rotatable',1)

But using drawpolygon, I don’t have the same flexibility and get an error if I add in rotatable. The variable “vertices” holds my x and y values.

h = drawpolygon('Position', vertices,'InteractionsAllowed', 'translate', 'LineWidth', 1);

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Here’s a solution that you can tweak to your liking. As demonstrated below, the code creates a red rotatable rectangle around the polygon object. Rotate the red rectangle and double click to confirm. The original polygon will rotate correspondingly.

imshow(ones(1000));
my_vertices = [500 500;400 600;400 700;500 800;600 800;700 700; 700 600];
h = drawpolygon('Position',my_vertices);
manualRotate(h);

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet