Edge Trimming¶
The edge trimming API provides post-processing for invalid border artifacts around nodata regions.
Import from coregix.postprocess:
1 | |
coregix.postprocess
¶
Post-processing utilities for aligned rasters.
EdgeTrimResult
dataclass
¶
Summary of edge trimming execution.
Attributes:
| Name | Type | Description |
|---|---|---|
output_image_path |
str
|
Path to the trimmed raster. |
nodata_value |
float
|
Nodata value used when writing trimmed pixels. |
pixels_trimmed |
int
|
Number of first-band pixels newly set to nodata. |
Source code in coregix/postprocess/edge_trim.py
16 17 18 19 20 21 22 23 24 25 26 27 28 | |
trim_edge_invalid_pixels(input_image_path, *, output_image_path=None, in_place=False, edge_depth=8, detection_band_index=0, invalid_below=None, invalid_above=None, nodata_value=None, row_chunk_size=1024, col_chunk_size=1024)
¶
Trim pixels adjacent to invalid raster regions.
The function detects invalid pixels from a selected band, dilates that
invalid mask by edge_depth pixels, and writes the resolved nodata value
to all bands wherever the trim mask is true. It can write a new raster or
update the input raster in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_image_path
|
str
|
Path to the raster to trim. |
required |
output_image_path
|
Optional[str]
|
Optional output raster path. Required unless
|
None
|
in_place
|
bool
|
If |
False
|
edge_depth
|
int
|
Number of pixels to trim around each invalid region. |
8
|
detection_band_index
|
int
|
0-based band index used to detect invalid pixels. |
0
|
invalid_below
|
Optional[float]
|
Optional threshold; values less than or equal to this value are treated as invalid. |
None
|
invalid_above
|
Optional[float]
|
Optional threshold; values greater than or equal to this value are treated as invalid. |
None
|
nodata_value
|
Optional[float]
|
Optional nodata override. Defaults to the raster's declared nodata value. |
None
|
row_chunk_size
|
int
|
Number of rows processed per window. |
1024
|
col_chunk_size
|
int
|
Number of columns processed per window. |
1024
|
Returns:
| Type | Description |
|---|---|
EdgeTrimResult
|
EdgeTrimResult summary with output path, nodata value, and pixel count. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If arguments are inconsistent or no invalid-pixel criteria are available. |
Source code in coregix/postprocess/edge_trim.py
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |