Function File: imcrop ()
Function File: imcrop (img)
Function File: imcrop (ind, cmap)
Function File: imcrop (h)
Function File: imcrop (…, rect)
Function File: [cropped] = imcrop (…)
Function File: [cropped, rect] = imcrop (…)
Function File: [x, y, cropped, rect] = imcrop (…)

Crop image.

Displays the image img in a figure window and waits for the user to select two points defining a bounding box. For an indexed image, a corresponding colormap can be specified in cmap. For multi-dimensional images (each 2D image is concatenated in the 4th dimension), only the first image is displayed.

If no image data is given, uses the current figure or figure from graphics handle h.

Non-interactive usage is supported if the last input argument is 4 element vector rect defining the region of interest. The first two elements specify the initial x_ini and y_ini coordinates, and the last two the width and height, i.e., rect = [x_ini y_ini width height]. Note how this the opposite of the majority of Octave indexing rules where rows come before columns.

Returns the cropped image and a vector rect with the coordinates and size for cropped. If more than 3 output arguments are requested, also returns the x and y data that define the coordinate system.

Note: the values in rect are not necessarily integer values and can’t always be used directly as index values for other images. To crop the same region from a multiple images of the same size, either using a multi-dimensional image:

nd_img = cat (4, img1, img2, img3, img4);
cropped = imcrop (nd_img);
cropped_1 = cropped(:,:,:,1);
cropped_2 = cropped(:,:,:,2);
cropped_3 = cropped(:,:,:,3);
cropped_4 = cropped(:,:,:,4);

or multiple calls to imcrop:

[cropped_1, rect] = imcrop (img1);
cropped_2         = imcrop (img2, rect);
cropped_3         = imcrop (img3, rect);
cropped_4         = imcrop (img4, rect);

See also: impixel, imshow.

Package: image