swectral.pixcount#

swectral.pixcount(image_path, roi_coordinates, band=1, threshold=None)[source]#

Count valid pixel number within a region of interest (ROI) within a threshold at a specific band.

Parameters:
image_pathstr

Spectral raster image path.

roi_coordinateslist of list of tuple of 2 (int or float)

Coordinates of the ROI polygons. Structure:

[
    [ (x1, y1), (x2, y2), ..., (xn, yn), (x1, y1) ],  # Polygon 1
    [ (x1, y1), (x2, y2), ..., (xm, ym), (x1, y1) ],  # Polygon 2
    ...
]

Each inner list represents a polygon (for multipart geometries), and each tuple is a vertex coordinate.

bandint, optional

Reference band, if threshold value is provided, values at this band is used for threshold.

thresholdtuple of 2 (int or float) or None, optional

The band value is compared with threshold, only pixel within the threshold are counted.

If None, all pixels within the ROI are counted regardless of their band values.

Returns:
int

Valid pixel number within a ROI whose value at the specified band does not exceed the threshold.

Return type:

int

Examples

>>> pixcount("/image1.tif", [[(0, 0), (10, 0), (0, 10), (0, 0)]], band=12)
>>> pixcount("/image1.tif", [[(0, 0), (10, 0), (0, 10), (0, 0)]], band=12, threshold=(1000, 3000))