Main Content

improfile

Pixel-value cross-sections along line segments

Description

Select Line Segments Interactively

c= improfilelets you select line segments interactively from the image in the current axes. When you finish selecting line segments,improfilereturns sampled pixel values along the line segments inc.

With this syntax, you specify the line or path using the mouse, by clicking points in the image. PressBackspaceor删除删除之前的ly selected point. To finish selecting points, adding a final point, press shift-click, right-click, or double-click. To finish selecting points without adding a final point, pressReturn.

c= improfile(n)returnsnsampled pixel values from line segments that you select interactively.

Select Line Segments by Specifying Endpoints

c= improfile(I,xi,yi)returns sampled pixel values along line segments in imageI. The endpoints of the line segments have (x,y) coordinatesxiandyi.

c= improfile(xref,yref,I,xi,yi)returns pixel values in the world coordinate system defined byxrefandyref. The line segment endpoints have (x,y) coordinatesxiandyiin this coordinate system.

c= improfile(___,n)returnsnsampled pixel values along the line segments.

Specify Interpolation Method or Output Options

c= improfile(___,method)specifies the interpolation method for pixel coordinates. Before themethodinput argument, you can specify the input arguments of any other syntax.

[cx,cy,c] = improfile(___)additionally returns the (x,y) coordinates of the sampled pixels,cxandcy. You can use the input arguments of any other syntax.

[cx,cy,c,xi2,yi2] = improfile(___)additionally returns the (x,y) coordinates of the line segment endpoints,xiandyi.

example

improfile (___)without output arguments displays a plot of pixel values along the line segments. If you select a single line segment, thenimprofilecreates a two-dimensional plot of intensity values versus the distance along the line segment. If you select two or more line segments, thenimprofilecreates a three-dimensional plot of the intensity values versus theirx- andy-coordinates.

Examples

collapse all

Read an image into the workspace, and display it.

I = imread('liftingbody.png'); imshow(I)

Figure contains an axes object. The axes object contains an object of type image.

Specifyx- andy-coordinates that define connected line segments.

x = [19 427 416 77]; y = [96 462 37 33];

Display a 3-D plot of the pixel values of these line segments.

improfile (I,x,y),gridon;

Figure contains an axes object. The axes object contains an object of type line.

Input Arguments

collapse all

Number of points to along the path to sample, specified as a positive integer. If you do not provide this argument, thenimprofilechooses a value fornthat is roughly equal to the number of pixels that the path traverses.

Data Types:double

Input image, specified as an RGB image, grayscale image, or binary image.

Data Types:single|double|int16|uint8|uint16|logical

x-coordinate of line segment endpoints, specified as a numeric vector of the same length asyi. If you specify image limits in a world coordinate system usingxref, thenxiis in this coordinate system. Otherwise,xiis in the default spatial coordinate system.

Data Types:double

y-coordinate of line segment endpoints, specified as a numeric vector of the same length asxi. If you specify image limits in a world coordinate system usingyref, thenyiis in this coordinate system. Otherwise,yiis in the default spatial coordinate system.

Data Types:double

Image limits in world coordinates along thex-dimension, specified as a 2-element numeric vector of the form [xminxmax]. The value ofxrefsets the imageXData. The data type ofxrefandyrefmust match.

Data Types:single|double

Image limits in world coordinates along they-dimension, specified as a 2-element numeric vector of the form [yminymax]. The value ofyrefsets the imageYData. The data type ofxrefandyrefmust match.

Data Types:single|double

Interpolation method, specified as'nearest'for nearest-neighbor interpolation,'bilinear', or'bicubic'.

Data Types:char|string

Output Arguments

collapse all

Sampled pixel values, returned as ann-by-1 numeric vector whenIis a grayscale or binary image, or ann-by-1-by-3 numeric array whenIis an RGB image.

Data Types:double

x-coordinate of sampled pixels, returned as ann-by-1 numeric vector.

Data Types:double

y-coordinate of sampled pixels, returned as ann-by-1 numeric vector.

Data Types:double

x-coordinate of line segment endpoints, returned as a numeric vector. If you specify line segment endpoints usingxi, thenxi2is equal toxi.

Data Types:double

y-coordinate of line segment endpoints, returned as a numeric vector. If you specify line segment endpoints usingyi, thenyi2is equal toyi.

Data Types:double

Version History

Introduced before R2006a