How to | Get Parts of an Image

Getting a rectangular part of an image is a very common and frequently needed image manipulation task. Several ways are presented here, including using the mouse.

This page requires that JavaScript be enabled in your browser.
Learn how »

Selected examples from the video:

The simplest way to get parts of an image is to use ImageCrop. By default, ImageCrop takes a subregion with the designated pixel width and height from the center of an image. Use ImageCrop to crop an image to pixel width 300 and pixel height 100:

A specific corner of the original image can be selected by cropping from the opposite corner. You can select the lower-left corner of an image by cropping the top-right portion:

Use ImageTake if you know the rows and columns you would like to extract from the original image. Take the first 100 rows of the image:

You can also use specific beginning and ending indices with ImageTake for precise region selection. Take the part of the image that occurs from rows 200 to 299, and columns 100 to 399:

ImageCrop and ImageTake complement each other, giving you a wide range of functionality. But what if you want to select the region of interest interactively, using a mouse or other pointing device? You can easily do this in a few quick steps.

With the mouse pointer positioned over an image, right-click and select Get Indices. The mouse pointer then changes into a cross with a tooltip next to it that indicates the current row and column position of the pointer.

Left-click the image in two locations, each representing diagonally opposite corners of the desired rectangular region. You can then simply Copy and Paste these coordinates into an input cell.

You can try this on the image here and then paste the coordinates into the next input:

Note that the coordinates are given in {{row1,column1},{row2,column2}} form:

Thread or transpose the indices to convert the list to the {{row1,row2},{column1,column2}} form required by ImageTake. The sort operation then ensures that the row and column lists are in ascending order, regardless of the order in which you picked the opposing corners of the rectangle:

Now take the selected region: