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_path
str Spectral raster image path.
- roi_coordinates
listoflistoftupleof2 (intorfloat) 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.
- band
int,optional Reference band, if
thresholdvalue is provided, values at this band is used forthreshold.- threshold
tupleof2 (intorfloat)orNone,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.
- image_path
- Returns:
intValid pixel number within a ROI whose value at the specified band does not exceed the threshold.
- Return type:
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))