Function File: axes2pix pixelCoord = axes2pix (n, extent, axesCoord)

Convert axes coordinates to pixel coordinates.

Converts coordinates axesCoord on a single axis in world units to intrinsic pixel coordinates of a 2-D image with n rows or columns, given a two-element real vector extent representing coordinates of centers of the first and last pixel in world units. Intrinsic pixel coordinates are always x = 1.0, y = 1.0 in the center of a top left pixel and x = number of columns, y = number of rows in the center of a bottom right pixel and are continuous. The actual coordinate range spanned by the image is larger than exntent by half a pixel on each side. For example if extent is [1, 2] and n is 2, the coordinate range spanned by the image on the axis is [0.5, 2.5].

Elements of the real vector axesCoord are trated as individual points on the axis. extent can also be given in reverse order.

MATLAB compatibility note: in order to produce results similar to MATLAB, very few argument validity checks are done. Octave will accept any scalar n (only positive integers make any sense), more-than-two-element vector extent (in which case only the first and last element are used), coordinates outside the the coordinate range spanned by the image (possibly resulting in negative pixel coordinates) or any matrix axesCoord. It’s up to the caller to provide sensible inputs.

## 800x600 pixel image with its top left pixel centered at (100, 0)
xData = [100, 140];
yData = [0, 30];
axes2pix(800, xData, [100, 120, 140])
⇒ 1.0 400.5 800.0
axes2pix(600, yData, [0, 15, 30])
⇒ 1.0 300.50 600.0
## x-axis reversed
xData = [140, 100];
axes2pix(800, xData, [100, 120, 140])
⇒ 800.0 400.5 1.0

Package: image