satsense.image

Methods for loading images.

class satsense.image.Image(filename, satellite, band='rgb', normalization_parameters=None, block=None, cached=None)[source]

Bases: object

Image class that provides a unified interface to satellite images.

Under the hood rasterio is used, so any format supported by rasterio can be used.

Parameters:
  • filename (str) – The name of the image
  • satellite (str) – The name of the satelite (i.e. worldview3, quickbird etc.)
  • band (str) – The band for the grayscale image, or ‘rgb’. The default is ‘rgb’
  • normalization_parameters (dict or boolean, optional) –

    if False no normalization is done. if None the default normalization will be applied (cumulative with 2, 98 percentiles)

    f a Dictionary that describes the normalization parameters The following keys can be supplied:

    • technique: string
      The technique to use, can be ‘cumulative’ (default), ‘meanstd’ or ‘minmax’
    • percentiles: list[int]
      The percentiles to use (exactly 2) if technique is cumulative, default is [2, 98]
    • numstds: float
      Number of standard deviations to use if technique is meanstd
  • block (tuple or rasterio.windows.Window, optional) – The part of the image read defined in a rasterio compatible way, e.g. two tuples or a rasterio.windows.Window object
  • cached (array-like or boolean, optional) – If True bands and base images are cached in memory if an array a band or base image is cached if its name is in the array

Examples

Load an image and inspect the shape and bands

from satsense import Image >>> image = Image(‘test/data/source/section_2_sentinel.tif’, ‘quickbird’) >>> image.shape (152, 155)

>>> image.bands
{'blue': 0, 'green': 1, 'red': 2, 'nir-1': 3}
>>> image.crs
CRS({'init': 'epsg:32643'})

See also

satsense.bands

itypes = {'canny_edge': <function get_canny_edge_image>, 'gray_ubyte': <function get_gray_ubyte_image>, 'grayscale': <function get_grayscale_image>, 'ndsi': functools.partial(<function ndxi_image>, ndxi_type='ndsi'), 'ndwi': functools.partial(<function ndxi_image>, ndxi_type='ndwi'), 'nir_ndvi': functools.partial(<function ndxi_image>, ndxi_type='nir_ndvi'), 'rb_ndvi': functools.partial(<function ndxi_image>, ndxi_type='rb_ndvi'), 'rg_ndvi': functools.partial(<function ndxi_image>, ndxi_type='rg_ndvi'), 'rgb': <function get_rgb_image>, 'texton_descriptors': <function get_texton_descriptors>, 'wvsi': functools.partial(<function ndxi_image>, ndxi_type='wvsi')}
classmethod register(itype, function)[source]

Register a new image type.

Parameters:
  • itype (str) – (internal) name of the image type
  • function – Function definition that should take a single Image parameter and return a numpy.ndarray or numpy.ma.masked_array

See also

ufunc:get_gray_ubyte_image
ufunc:get_grayscale_image
ufunc:get_rgb_image
copy_block(block)[source]

Create a subset of Image.

Parameters:block (tuple or rasterio.windows.Window) – The part of the image to read defined in a rasterio compatible way, e.g. two tuples or a rasterio.windows.Window object
Returns:subsetted image
Return type:image.Image
__getitem__(itype)[source]

Get image of a type registered using the register method. The following itypes are available to facilitate creating new features: - ‘rgb’ - ‘grayscale’ - ‘gray_ubyte’

Parameters:itype (str) – The name of the image type to retrieve
Returns:out – The image of the supplied type
Return type:numpy.ndarray or numpy.ma.masked_array

Examples

Get the rgb image >>> image[‘rgb’].shape (152, 155, 3) >>> image[‘gray_ubyte’].dtype dtype(‘uint8’)

precompute_normalization(*bands)[source]

Precompute the normalization of the image

Normalization is done using the normalization_parameters supplied during class instantiation. Normalization parameters are computed automatically for all bands when required, but doing it explicitly can save some time, e.g. if there are more bands in the image than needed.

Parameters:*bands (list[str] or None) – The list of bands to normalize, if None all bands will be normalized
Raises:ValueError: – When trying to compute the normalization on a partial image, as created by using the copy_block method.

See also

Image()
func:_normalize Get normalization limits for band(s).
shape

Provide shape attribute.

crs

Provide crs attribute.

transform

Provide transform attribute.

scaled_transform(step_size)[source]

Perform a scaled transformation.

Returns:out – An affine transformation scaled by the step size
Return type:affine.Affine
satsense.image.get_rgb_image(image: satsense.image.Image)[source]

Convert the image to rgb format.

Parameters:image (image.Image) – The image to calculate the rgb image from
Returns:The image converted to rgb
Return type:numpy.ndarray
satsense.image.get_grayscale_image(image: satsense.image.Image)[source]

Convert the image to grayscale.

Parameters:image (image.Image) – The image to calculate the grayscale image from
Returns:The image converted to grayscale in 0 - 1 range
Return type:numpy.ndarray

See also

skimage.color.rgb2gray()
Used to convert rgb image to grayscale
satsense.image.get_gray_ubyte_image(image: satsense.image.Image)[source]

Convert image in 0 - 1 scale format to ubyte 0 - 255 format.

Parameters:image (image.Image) – The image to calculate the grayscale image from
Returns:The image converted to grayscale
Return type:numpy.ndarray

See also

skimage.img_as_ubyte()
Used to convert the image to ubyte
class satsense.image.FeatureVector(feature, vector, crs=None, transform=None)[source]

Bases: object

Class to store a feature vector in.

Parameters:
  • feature (satsense.feature.Feature) – The feature to store
  • vector (array-like) – The data of the computed feature
  • crs – The coordinate reference system for the data
  • transform (Affine) – The affine transformation for the data
get_filename(window, prefix='', extension='nc')[source]

Construct filename from input parameters.

Parameters:
  • window (tuple) – The shape of the window used to calculate the feature
  • prefix (str) – Prefix for the filename
  • extension (str) – Filename extension
Returns:

Return type:

str

save(filename_prefix='', extension='nc')[source]

Save feature vectors to files.

Parameters:
  • filename_prefix (str) – Prefix for the filename
  • extension (str) – Filename extension
  • Returns – 1-D array-like (str)
classmethod from_file(feature, filename_prefix)[source]

Restore saved features.

Parameters:
  • feature (Feature) – The feature to restore from a file
  • filename_prefix (str) – The directory and other prefixes to find the feature file at
Returns:

The feature loaded into a FeatureVector object

Return type:

satsense.image.FeatureVector