FigCrop

Crops a surface image (e.g. generated by SURF or MESH) to a specified rectangle.
2.1K Downloads
Updated 24 Feb 2003

No License

%function varargout = figcrop(varargin)
% jdc 20-feb-03
%PURPOSE:
% FIGCROP crops a surface image (e.g. generated by SURF or MESH) to
% a specified rectangle. Alternately displays the input image and waits for
% you to specify the crop rectangle with the mouse, or crops to an
% input-defined rectangle.
% Requires GETRECT.M (in Images toolbox)
%INPUT:
% FigCrop - operates on current surface object in current figure
% Figcrop(matrix) - operates on a specified matrix
% Figcrop(matrix,map) - operates on a matrix with a specified colormap
% Figcrop(matrix,rectangle) - operates on a matrix with specified crop rectangle
% Figcrop(matrix,colormap,rectangle) - matrix with specified colormap & rectangle
%
% Figcrop(handle) - operates on object specified by handle
% (handle can be to a figure, axes, or surface object)
% Figcrop(handle,map) - handle with specified colormap
% Figcrop(handle,rectangle) - ... handle with specified crop rectangle
% Figcrop(handle,colormap,rectangle) - handle with specified colormap & rectangle
%
% Crop rectangle not specified: click & drag left mouse button to define region of
% interest: use the right mouse button to enforce a
% square region of interest.
% Crop rectangle specified: region of interest taken as interior of defined rectangle
%
%OUTPUT:
% [B,RECT] = FIGCROP(...) - output is cropped matrix plus rectangle
% [X,Y,B,RECT] = FIGCROP(...) - as above, plus Xdata and Ydata from source object
%
% B - trimmed output matrix
% RECT - 4-element vector with the form [XMIN YMIN WIDTH HEIGHT], in spatial coordinates.
% X - Xdata from the input matrix
% Y - Ydata from the input matrix

%CLASS SUPPORT:
% The input matrix can be of class uint8, uint16, or double.
% The output image B is of the same class as the input image.
% RECT is always of class double.
%
%EXAMPLES
% assuming 128x128 matrix PLATHONE in memory,
%#1) [cropped,rect] = figcrop(plathone);
%#2) [plathonecropped,rectangle] = figcrop(plathone,[20 30 40 50]);
%
% See also IMCROP

Cite As

J. Cogdell (2024). FigCrop (https://www.mathworks.com/matlabcentral/fileexchange/3045-figcrop), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0