Raster Features API¶
obia.features.extract.extract_features(segments, image, *, bands=None, spectral=SPECTRAL_FEATURES, percentiles=(10, 90), indices=None, shape=(), shape_units='map', texture=None, mask=None)
¶
Add selected features to a copy of an existing segment table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
GeoDataFrame
|
Polygon GeoDataFrame in the raster CRS. Its IDs, index, geometry, and existing attributes are preserved. Requested feature columns replace columns with the same names when recalculating. |
required |
image
|
Image
|
OBIA Image; calculations use its loaded (height, width, bands) values, including their selected order, rather than rereading files. |
required |
bands
|
tuple[int, ...] | None
|
Zero-based band indices for spectral statistics and, by default, texture. None selects all loaded bands; () selects none. |
None
|
spectral
|
tuple[str, ...]
|
Names in |
SPECTRAL_FEATURES
|
percentiles
|
tuple[float, ...]
|
Additional percentiles in [0, 100], using linear interpolation. Use () to disable them. Applied to bands and calculated indices. |
(10, 90)
|
indices
|
dict[str, tuple[int, ...]] | None
|
Index names mapped to ordered numeric band indices, e.g. {'ndvi': (3, 0)}. Indices are computed per pixel before summarization. |
None
|
shape
|
tuple[str, ...] | bool
|
Names in |
()
|
shape_units
|
str
|
'map' requires a projected CRS and uses its coordinate units; 'pixel' uses the inverse raster transform, including rotation/shear. |
'map'
|
texture
|
TextureConfig | None
|
Optional texture configuration. Ranges are fitted once per band over finite included image pixels, or supplied explicitly. |
None
|
mask
|
ndarray | None
|
Optional boolean (height, width) mask. False pixels contribute to neither distributions nor texture. Geometry itself is unchanged. |
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: Feature columns prefixed bN_, index_METHOD_bN_..., or shape_. Undefined measurements are NaN, valid counts are zero for objects without samples. Configuration and fitted texture ranges are recorded in attrs['obia_features'] (in-memory metadata). |
Source code in obia/features/extract.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
obia.features.spectral.compute_index(data, method, bands)
¶
Calculate a spectral index from explicit zero-based band indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Raster array shaped (height, width, bands), optionally masked. |
required |
method
|
str
|
Name in |
required |
bands
|
tuple[int, ...]
|
Ordered numeric band indices. No wavelengths are inferred. For example, ndvi with (3, 0) calculates (b3-b0)/(b3+b0). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A float64 index image. Masked/nonfinite operands, zero denominators, and nonfinite results become NaN. Input is unchanged. |
Source code in obia/features/spectral.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
obia.features.texture.TextureConfig
dataclass
¶
Choose texture bands, spatial scales, directions, and quantization.
Attributes:
| Name | Type | Description |
|---|---|---|
bands |
tuple[int, ...] | None
|
Zero-based band indices; None uses the extraction's selected bands. |
features |
tuple[str, ...]
|
GLCM feature names; an empty tuple disables GLCM calculations. |
distances |
tuple[int, ...]
|
Positive integer pixel distances, reported separately. |
angles |
tuple[float, ...]
|
Directions in radians, measured from increasing columns toward increasing rows. With angle_aggregation='none', output a0, a1, ... refer to positions in this tuple. |
levels |
int
|
Number of uniformly spaced gray levels, between 2 and 256. |
value_range |
tuple[float, float] | None
|
Fixed (minimum, maximum), or None for each band's finite range over the entire included image. Never fitted per object. |
symmetric |
bool
|
Include both pair orders in each co-occurrence matrix. |
angle_aggregation |
str
|
'mean' averages available directions; 'none' retains each direction. A direction with no valid pixel pairs is NaN. |
entropy_radii |
tuple[int, ...]
|
Positive integer radii for disk-shaped local entropy windows. Their mean and population standard deviation are reported. |
Source code in obia/features/texture.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
Available feature names can be inspected with SPECTRAL_FEATURES,
SPECTRAL_INDICES, SHAPE_FEATURES, and GLCM_FEATURES from obia.features.
See the raster feature guide for formulas, units,
mask handling, and configuration examples.