making a rectangle with one mouse click
Show older comments
I work in matlab with a code that was already made by somebody else. In this code you can choose to form a rectangle area with the code ginput, so in my image I click one two spots to form a rectangle and then the code goes further:
if PickRegion==1
fprintf('Pick two corners to indicate the region for tracking \n')
figure(1);
[xreg yreg] = ginput(2); %2 points
if (length(xreg) < 2)
return%break
end
rect=[min(xreg) min(yreg) abs(xreg(2)-xreg(1)) abs(yreg(2)-yreg(1))] %rect:[left low xsize ysize]
end
Now I would like to form the same size rectangle everytime but be able to choose where to place it, so that in different images the size of the rectangle is always the same. So that with one mouse click I can choose for example the upper right corner and then a fixed size rectangle is formed. How should I go about making this code, can anybody help?
Thanks in advance !
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!