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:

Click for copyable input

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:

Click for copyable input

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:

Click for copyable input

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:

Click for copyable input

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:

Click for copyable input
Click for copyable input

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

Click for copyable input

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:

Click for copyable input

Now take the selected region:

Click for copyable input


Related Demonstrations

See Also

ImageCrop  ImageTake