IMRECT: constrain rectangle heght to be a multiple of another value
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Hi, Please help me end three days of frustration....I need to be able to:
- Overlay a rectangle on an image using imrect (does not have to be imrect but this is what I am using, I am open to change)
- Allow the user to modify the upper and lower bounds (height) of the rectangle
- When either lower or upper bound is modified, find the the new 'height' (e.g. 25pixels)
- Constrain the height to be an integer multiple of a certain pre-determined value (e.g. n*20pixels) - therefore automatically modify the height into a multiple of the pre-determined value (i.e. auto-change to 40)
Thanks, Dominic
Respuestas (3)
Image Analyst
el 17 de Abr. de 2013
Three days? Don't you just call imrect() and then the user clicks to accept it, and then you just get the coordinates and quantize them to the nearest multiple of 20? It's just a few lines of code, isn't it? Three minutes of work got me this:
% imrect Example 2
% Interactively place a rectangle by clicking and dragging.
% Use wait to block the MATLAB command line.
% Double-click on the rectangle to resume execution of the MATLAB command line.
imshow('pout.tif');
h = imrect;
position = wait(h);
delete(h);
% Now quantize width and height.
quantizedWidth = position(3) - rem(position(3), 20)
quantizedHeight = position(4) - rem(position(4), 20)
x1 = position(1);
y1 = position(2);
x2 = x1 + quantizedWidth - 1;
y2 = y1 +quantizedHeight - 1;
rectangle('Position', [x1, y1, quantizedWidth, quantizedHeight], 'EdgeColor', [1 1 0]);
Sean de Wolski
el 17 de Abr. de 2013
0 votos
This sounds like it might be possible with the setFixedAspectRatioMode of the imrect() object. Then the aspect ratio will never change no matter what they do.
Dominic
el 21 de Mayo de 2013
0 votos
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!