How can I crop next image in same size of previous but difference position.
6 views (last 30 days)
Show older comments
Hi all
My purpose is get two matrix of image in same size
I'd like to crop 2 image in same size but difference position.
My method is crop first image and keep first image size as [m n]. Then, I'd live to crop second image in same size of [m n] but difference position. So i have tried
"a=imcrop(image,[0 0 m n])"
but it just automatically crop and I can't fix certain position of x and y, because the object is difference position from origin point.
How can i control certain size of image crop but still move crop region on figure then we can choose where to crop it.
0 Comments
Accepted Answer
Image Analyst
on 15 Nov 2012
Try this
message = sprintf('Click the upper left corner of the cropping box');
uiwait(msgbox(message));
[x, y] = ginput(1); % Ask user to click the upper left corner.
croppedImage = imcrop(currentImage, [x, y, m, n]);
0 Comments
More Answers (2)
Biswajit Manna
on 30 Jan 2014
Edited: Biswajit Manna
on 30 Jan 2014
This code may solve your problem.
function [ I_crop ] = b_croprect( imageG )
%b_croprect Summary of this function goes here
% Detailed explanation goes here
% input is an gray image
% output is an croped image
imshow(imageG);
h = imrect(gca, [50 50 511 511]); % create rectangle on the image
message = sprintf('Drag, set position of the rectangle cropping box and double click on the rectangle box');
uiwait(msgbox(message));
position = wait(h); % get position
I_crop = imcrop(imageG,position); % crop image
message = sprintf('Image has been croped');
msgbox(message);
end
0 Comments
Walter Roberson
on 15 Nov 2012
a = imcrop(image, [X Y m n])
where X is the column and Y is the row of the lower-left corner of where you want the cropping to start, and m is the width and n is the height you want the cropped image to be.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!