Documentation Center

  • Trial Software
  • Product Updates

Measure Distance Between Pixels in Image Viewer

Determine Distance Between Pixels Using Distance Tool

  1. Display an image in the Image Viewer.

    imtool('moon.tif') 
  2. Click the Distance tool button in the Image Viewer toolbar or select Measure Distance from the Tools menu. The Distance tool allows you to measure distance with a click-and-drag approach. When you move the pointer over the image, the pointer changes to cross hairs . Position the cross hairs at the beginning of the region you wish to measure, hold down the mouse button, drag the cross hairs to the end of the region, and release the button.

    The Distance tool displays the Euclidean distance between the two endpoints of the line in a label superimposed over the line. The tool specifies the distance in data units determined by the XData and YData properties, which is pixels, by default.

  3. An alternative to using the Distance tool in Image Viewer is to open a figure window using imshow and then call imdistline. The Distance tool appears as a horizontal line displayed over the image. You can reposition the line or grab either of its endpoints to resize the tool.

Export Endpoint and Distance Data

To save the endpoint locations and distance information, right-click the Distance tool and choose the Export to Workspace option from the context menu. The Distance tool opens the Export to Workspace dialog box. You can use this dialog box to specify the names of the variables used to store this information.

After you click OK, the Distance tool creates the variables in the workspace, as in the following example.

whos
  Name          Size            Bytes  Class     Attributes

  distance      1x1                 8  double              
  point1        1x2                16  double              
  point2        1x2                16  double 

Customize the Appearance of the Distance Tool

Using the Distance tool context menu, you can customize many aspects of the Distance tool appearance and behavior. Position the pointer over the line and right-click to access these context menu options.

  • Toggling the distance tool label on and off using the Show Distance Label option.

  • Changing the color used to display the Distance tool line using the Set color option.

  • Constraining movement of the tool to either horizontal or vertical using the Constrain drag option.

  • Deleting the distance tool object using the Delete option.

Right-click the Distance tool to access this context menu.

Was this topic helpful?