matlab - crop image with fixed x/y ratio -


i want crop image using following code. want user can select crop area predefined x/y ratio.for example if x=2,y=2 ,then user can use mouse select area (x/y)=1 ratio.

i = imread('image.jpg'); [rows columns numberofcolorbands] = size(i); i2 = imcrop(i); imshow(i), figure, imshow(i2) 

you use imrect produce coordinates, , pass imcrop.

figure, imshow(i); h = imrect(gca,[10 10 100 100]);  setfixedaspectratio(h,1); % fixes aspect ratio; user can change size/position position = wait(h); % returns coordinates in "position" when user doubleclicks on rectangle i2 = imcrop(i,position); figure, imshow(i2); 

in actual code, you'll have replace [10 10 100 100] of appropriate size/aspect ratio images. may want add other constraints imrect (for example stop user moving rectangle outside actual image).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -