Image Processing Toolbox User's Guide Previous page   Next Page

Cropping an Image

To extract a rectangular portion of an image, use the imcrop function. imcrop accepts two primary arguments:

If you call imcrop without specifying the crop rectangle, you can specify the crop rectangle interactively. In this case, the cursor changes to crosshairs when it is over the image. Position the crosshairs over a corner of the crop region and press and hold the left mouse button. When you drag the crosshairs over the image you specify the rectangular crop region. imcrop draws a rectangle around the area you are selecting. When you release the mouse button, imcrop creates a new image from the selected region.

In this example, you display an image and call imcrop. The imcrop function displays the image in a figure window and waits for you to draw the cropping rectangle on the image. In the figure, the rectangle you select is shown in red. The example then calls imshow to view the cropped image.


Previous page  Rotating an Image Performing General 2-D Spatial Transformations Next page

© 1994-2005 The MathWorks, Inc.