pybob.image_tools

pybob.image_tools is a collection of tools related to working with images.

pybob.image_tools.create_mask_from_shapefile(geoimg, shapefile, buffer=None)[source]

Create a boolean mask representing the polygons in a shapefile.

Parameters:
  • geoimg (pybob.GeoImg) – input GeoImg to pull spatial extents from
  • shapefile (str) – path to polygon shapefile
Returns mask:

boolean array corresponding to rasterized polygons, of same shape as geoimg.img

pybob.image_tools.hillshade(dem, azimuth=315, altitude=45)[source]

Create a hillshade image of a DEM, given the azimuth and altitude.

Parameters:
  • dem (pybob.GeoImg) – GeoImg representing a DEM.
  • azimuth (float) – Solar azimuth angle, in degress from North. Default 315.
  • altitude (float) – Solar altitude angle, in degrees from horizon. Default 45.
Returns shade:

numpy array of the same size as dem.img, representing the hillshade image.

pybob.image_tools.nanmedian_filter(img, **kwargs)[source]

Calculate a multi-dimensional median filter that respects NaN values and masked arrays.

Parameters:
  • img (array-like) – image on which to calculate the median filter
  • kwargs – additional arguments to ndimage.generic_filter Note that either size or footprint must be defined. size gives the shape that is taken from the input array, at every element position, to define the input to the filter function. footprint is a boolean array that specifies (implicitly) a shape, but also which of the elements within this shape will get passed to the filter function. Thus size=(n,m) is equivalent to footprint=np.ones((n,m)). We adjust size to the number of dimensions of the input array, so that, if the input array is shape (10,10,10), and size is 2, then the actual size used is (2,2,2).
Returns filtered:
 

Filtered array of same shape as input.

pybob.image_tools.rasterize_polygons(geoimg, shapefile, burn_handle=None, dtype=<MagicMock name='mock.GDT_Int16' id='140228516065520'>)[source]

Create rasterized polygons given a GeoImg and a shapefile. Useful for creating an index raster with corresponding to polygon IDs.

Parameters:
  • geoimg (pybob.GeoImg) – input GeoImg to pull spatial extents from.
  • shapefile (str) – path to polygon shapefile
  • burn_handle (str) – field to pull values to rasterize. Default looks for the FID field in the shapefile.
  • dtype (gdal.GDT) – gdal datatype of rasterized layer. Default is gdal.GDT_Int16.
Returns rasterized, inds:
 

rasterized polygon array and values corresponding to polygons that were rasterized.