Main Content

pixcenters

(Removed) Compute pixel centers for georeferenced image or data grid

The pixcenters function has been removed. Use the geographicGrid or worldGrid function instead. For more information, see Version History.

Syntax

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

Description

[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 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 structure array with the fields

'RefMatrix'

3-by-2 referencing matrix

'Height'

Scalar number

'Width'

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.

Examples

[Z,R] = readgeoraster('MtWashington-ft.grd','OutputType','double'); 
info = georasterinfo('MtWashington-ft.grd'); 
Z = standardizeMissing(Z,info.MissingDataIndicator);
figure
[x,y] = pixcenters(R,size(Z));
h = surf(x,y,Z);
axis equal
demcmap(Z)
set(h,'EdgeColor','none')
xlabel('x (easting in meters)')
ylabel('y (northing in meters)')
zlabel('elevation in feet')

Tips

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

Version History

Introduced before R2006a

expand all

R2024a: Errors

Some functions that accept referencing matrices as input have been removed, including the pixcenters function. Use a raster reference object and the geographicGrid or worldGrid function instead. Reference objects have several advantages over referencing matrices.

  • Unlike referencing matrices, reference objects have properties that document the size of the associated raster, its limits, and the direction of its rows and columns. For more information about reference object properties, see the GeographicCellsReference and MapCellsReference objects.

  • You can manipulate the limits of rasters associated with reference objects using the geocrop or mapcrop function.

  • You can manipulate the size and resolution of rasters associated with reference objects using the georesize or mapresize function.

  • Most functions that accept referencing matrices as inputs also accept reference objects.

Depending on the pixcenters function syntax, there are different ways to update your code.

  • If the raster is referenced to projected x-y coordinates, use a map raster reference object and the worldGrid function. This table shows replacement patterns for the pixcenters function syntaxes that specify a referencing matrix refmat, scalar structure info, or GeoTIFF information structure geoinfo. Note that the default behavior of the pixcenters function is to return row vectors and the default behavior of the worldGrid function is to return 2-D arrays. To return row vectors using the worldGrid function, specify the second argument as 'gridvectors'.

    RemovedRecommended
    [X,Y] = pixcenters(refmat,height,width);
    R = refmatToMapRasterReference(refmat, ...
       [height width]);
    [X,Y] = worldGrid(R,'gridvectors');
    [X,Y] = pixcenters(refmat,rasterSize);
    R = refmatToMapRasterReference(refmat,rasterSize);
    [X,Y] = worldGrid(R,'gridvectors');
    [X,Y] = pixcenters(info);
    R = refmatToMapRasterReference( ...
        info.RefMatrix, [info.Height info.Width]);
    [X,Y] = worldGrid(R, ...
        'gridvectors');
    [X,Y] = pixcenters(geoinfo);
    [X,Y] = worldGrid(geoinfo.SpatialRef, ...
        'gridvectors');

    If the TransformationType property of the reference object R is 'affine', the [x,y] = worldgrid(R,'gridvectors') syntax displays a warning. Temporarily suppress the warning by including this code before the call to the worldGrid function.

    w = warning('off','map.spatialref.fullGridForAffine');
    c = onCleanup(@() warning(w));

  • If the raster is referenced to latitude and longitude coordinates, use a geographic raster reference object and the geographicGrid function. This table shows replacement patterns for function syntaxes that specify a referencing matrix refmat or scalar structure info. Note that the default behavior of the pixcenters function is to return row vectors and the default behavior of the geographicGrid function is to return 2-D arrays. To return row vectors using the geographicGrid function, specify the second argument as 'gridvectors'.

    RemovedRecommended
    [lon,lat] = pixcenters(refmat,height,width);
    R = refmatToGeoRasterReference(refmat, ...
        [height width]);
    [lat,lon] = geographicGrid(R,'gridvectors');
    [lon,lat] = pixcenters(refmat,rasterSize);
    R = refmatToGeoRasterReference(refmat,rasterSize);
    [lat,lon] = geographicGrid(R,'gridvectors');
    [lon,lat] = pixcenters(info);
    R = refmatToGeoRasterReference( ...
        info.RefMatrix, [info.Height info.Width]);
    [lat,lon] = geographicGrid(R,'gridvectors');