Measuring the Distance Between Two Pixels

Using the Distance Tool

  1. Display an image in the Image Tool.

    imtool('moon.tif') 
  2. Click the Distance tool button in the Image Tool 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 Tool 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.

Exporting 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

  distance       1x1                         8  double array
  moon         537x358                  192246  uint8 array
  point1         1x2                        16  double array
  point2         1x2                        16  double array

Customizing 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.

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

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS