How to select and crop a particular region from the image?
293 views (last 30 days)
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)));
More Answers (1)
Josep Llobet on 23 Jul 2021
You can select just the regions of the matrix that define your image, as follows:
img_cropped = img(300:450, 500:600);
In the example, you will select the image in the regions between 300 and 450 of the x axis, and the 500 to 600 in the y axis.
If you want to know the size of the matrix which define your image, you can use size()
Hope this will be useful!!