MATLAB Answers

How to select and crop a particular region from the image?

249 views (last 30 days)
Jonathan on 18 Aug 2015
Commented: piku mandal on 1 Oct 2018
After some filtering, I manage to get this image,
My question is, how do you select and hopefully crop the region of interest? So I can get something like this.
Many thanks,


Sign in to comment.

Accepted Answer

blaat on 18 Aug 2015
Edited: blaat on 18 Aug 2015
If you have the Image Processing Toolbox, you can use the function imrect() to select a rectangular area from your image. For example:
h_rect = imrect();
% Rectangle position is given as [xmin, ymin, width, height]
pos_rect = h_rect.getPosition();
% Round off so the coordinates can be used as indices
pos_rect = round(pos_rect);
% Select part of the image
img_cropped = img(pos_rect(2) + (0:pos_rect(4)), pos_rect(1) + (0:pos_rect(3)));

  1 Comment

piku mandal
piku mandal on 1 Oct 2018
but how to use it for live images that is come from camera?

Sign in to comment.

More Answers (0)

Sign in to answer this question.