Compute pixel centers for georeferenced image or data grid


[x,y] = pixcenters(R, height, width)
[x,y] = pixcenters(r,sizea)
[x,y] = pixcenters(..., 'makegrid')


[x,y] = pixcenters(R, height, width) returns the spatial coordinates of a spatially-referenced image or regular gridded data set. R is either a 3-by-2 referencing matrix defining a 2-dimensional affine transformation from intrinsic pixel coordinates to map coordinates, or a map.rasterref.MapCellsReference object. height and width are the image dimensions. If r does not include a rotation (i.e., r(1,1) = r(2,2) = 0), then x is a 1-by-width vector and y is a 1-by-height vector. In this case, the spatial coordinates of the pixel in row row and column col are given by x(col), y(row). Otherwise, x and y are each a height-by-width matrix such that x(col,row), y(col,row) are the coordinates of the pixel with subscripts (row,col).

[x,y] = pixcenters(r,sizea) accepts the size vector sizea = [height, width, ...] instead of height and width.

[x,y] = pixcenters(info) accepts a scalar struct array with the fields


3-by-2 referencing matrix


Scalar number


Scalar number

[x,y] = pixcenters(..., 'makegrid') returns x and y as height-by-width matrices even if r is irrotational. This syntax can be helpful when you call pixcenters from within a function or script.


[Z,R] = arcgridread('MtWashington-ft.grd');
[x,y] = pixcenters(R, size(Z));
h = surf(x,y,Z); axis equal; demcmap(Z)
xlabel('x (easting in meters)')
ylabel('y (northing in meters)')
zlabel('elevation in feet')

More About

expand all


For more information on referencing matrices, see the makerefmat reference page.

pixcenters is useful for working with surf, mesh, or surface, and for coordinate transformations.

Was this topic helpful?