Restore¶
Denoising, despeckling, destriping, gap-fill, and inpainting operators.
- Denoising:
BilateralDenoise,GaussianDenoise,MedianDenoise,NLMeans,DenoisePCA,MNF(minimum noise fraction, Green et al. 1988;fit/transform/inverse) - SAR despeckle:
DespeckleLee(Lee 1980),DespeckleRefinedLee,DespeckleFrost(Frost 1982) - Destripe:
DestripeColumn,MomentMatching(per-column gain + offset, Gadallah et al. 2000) - Gap fill:
GapFillNearest,GapFillIDW,GapFillInpaintBiharmonic,GapFillLaplacian - Outlier handling:
OutlierMask,ReplaceOutliers(saturation flags:geoops.qa.MaskSaturated) - Tier-A primitives:
bilateral_denoise,gaussian_denoise,median_denoise,nl_means,pca_denoise,despeckle_lee,despeckle_refined_lee,despeckle_frost,destripe_column,gap_fill_nearest,gap_fill_idw,gap_fill_biharmonic,gap_fill_laplacian,outlier_mask,replace_outliers
geoops.restore
¶
Restoration primitives and Operators for imperfect remote-sensing data.
BilateralDenoise
¶
Bases: Operator
Edge-aware denoise using a range-weighted Gaussian.
Wraps :func:~geoops.restore._src.array.bilateral_denoise. Use
sigma_color to control how aggressively edges are preserved
(smaller = stronger preservation) and sigma_space for the
spatial smoothing scale.
Caveat: this is a single-pass approximation of a full bilateral filter, not the canonical per-pixel-neighbourhood form. Nodata (fill / non-finite) pixels are excluded from the smoothing and hold the output fill.
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
DenoisePCA
¶
Bases: Operator
Reconstruct a multi-band raster from its top PCA components.
Projects the carrier onto its leading n_components principal
directions and reconstructs in the original space. Effective at
suppressing band-uncorrelated noise; can soften sharp
band-localised features. The components are fitted on valid pixels
only (a pixel invalid in any band is excluded); invalid pixels hold
the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
Number of principal components to keep.
|
required |
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Inputs are (C, H, W) cubes or (T, C, H, W) stacks; a stack is
fitted once over the pixels of every frame (one PCA basis for the
time series). A 2-D (H, W) map has no band axis and raises
ValueError -- its rows are never treated as bands.
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
DespeckleFrost
¶
Bases: Operator
Frost (1982) adaptive exponential-kernel speckle filter.
Wraps :func:~geoops.restore._src.array.despeckle_frost: a
normalised weighted window mean with kernel
m(t) = exp(−K·Cᵥ²·|t|), where Cᵥ² = σ_z²/z̄² is the local
squared coefficient of variation and |t| the distance from the
centre pixel. The kernel is wide on homogeneous speckle and narrows
onto the centre pixel at edges. Nodata (fill / non-finite) pixels
get zero weight and hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
Side length of the kernel window in pixels. |
7
|
damping
|
float
|
Damping factor |
2.0
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
DespeckleLee
¶
Bases: Operator
Lee (1980) local-statistics speckle filter.
Carrier-aware wrapper around
:func:~geoops.restore._src.array.despeckle_lee:
x̂ = z̄ + k·(z − z̄) with the MMSE gain
k = σ_x² / (σ_x² + Cᵤ²·z̄²), σ_x² = (σ_z² − Cᵤ²·z̄²) / (1 + Cᵤ²)
clipped at 0 -- the local mean on homogeneous speckle, k → 1
(pass-through) at edges. Best suited to multiplicative speckle in SAR
imagery. Nodata (fill / non-finite) pixels are excluded from the
window statistics and hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
Side length of the local window in pixels. |
7
|
cu
|
float
|
Noise coefficient of variation |
0.523
|
Examples:
>>> import geoops as gz
>>> pipe = gz.restore.DespeckleLee(window=7) | gz.restore.MedianDenoise(window=3)
>>> clean = pipe(sar_geoarray)
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
DespeckleRefinedLee
¶
Bases: Operator
Refined-Lee speckle filter approximation.
Wraps :func:~geoops.restore._src.array.despeckle_refined_lee.
This is currently a dependency-light alias for :class:DespeckleLee
(Lee 1980 gain) with default cu; the eight-direction sub-window selection of the
canonical Refined-Lee is not yet implemented. Nodata pixels are
handled as in :class:DespeckleLee.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
Side length of the local window in pixels. |
7
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
DestripeColumn
¶
Bases: Operator
Subtract per-column (or per-row) offsets from striped imagery.
Wraps :func:~geoops.restore._src.array.destripe_column. Use
method="mean" for additive stripes, "median" for stripes
with outlier contamination, and "moment_matching" for stripes
with a per-detector gain and offset: every column is linearly
rescaled so its mean and standard deviation match a reference
((z − μ_j)·σᵣ/σ_j + μᵣ; the moving average of the column moments
over window columns, or global with window=None). Nodata
(fill / non-finite) pixels are excluded from the column / row
statistics and hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['mean', 'median', 'moment_matching']
|
|
'mean'
|
direction
|
Literal['column', 'row']
|
Striping direction. |
'column'
|
window
|
int | None
|
Reference window (in columns / rows) for
|
21
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
GapFillIDW
¶
Bases: Operator
Fill NaNs with inverse-distance weighted finite neighbours.
Wraps :func:~geoops.restore._src.array.gap_fill_idw (functax plans,
the [interp] extra). NaNs whose
neighbourhood within radius contains no finite pixels are left
unfilled — chain with :class:GapFillNearest for unconditional fill.
Nodata elements (fill value or non-finite) are the gaps: the output
there is the filled value, not the fill value; only gaps left
unfilled hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power
|
float
|
IDW exponent. |
2.0
|
radius
|
int
|
Search radius in pixels. |
5
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
GapFillInpaintBiharmonic
¶
Bases: Operator
Smoothly inpaint NaN gaps with a biharmonic fill (Δ²u = 0).
Wraps :func:~geoops.restore._src.array.gap_fill_biharmonic
(functax.project.fill_gaps, the [interp] extra), which solves
Δ²u = 0 in the holes and preserves the original finite pixels — the
operator just round-trips carrier metadata.
Nodata elements (fill value or non-finite) are the gaps: the output
there is the filled value, not the fill value; only gaps left
unfilled hold the output fill.
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
GapFillLaplacian
¶
Bases: Operator
Fill NaNs by solving a discrete Laplace equation.
Wraps :func:~geoops.restore._src.array.gap_fill_laplacian
(functax.project.fill_gaps, the [interp] extra). The
harmonic interpolant, solved exactly — smooth, but linearly biased
toward the mean of the boundary. Pair with :class:GaussianDenoise
for a smoother transition near the mask edge.
Nodata elements (fill value or non-finite) are the gaps: the output
there is the filled value, not the fill value; only gaps left
unfilled hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterations
|
int | None
|
Deprecated and ignored: the fill is an exact solve, not a fixed number of Jacobi sweeps. Passing it warns. |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
GapFillNearest
¶
Bases: Operator
Fill NaNs from the nearest finite neighbour.
Wraps :func:~geoops.restore._src.array.gap_fill_nearest (functax
plans, the [interp] extra). Unconditional unless max_distance
is set.
Nodata elements (fill value or non-finite) are the gaps: the output
there is the filled value, not the fill value; only gaps left
unfilled hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_distance
|
int | None
|
Maximum Euclidean fill radius in pixels. |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
spatial_reach()
¶
The spatial reach in pixels: unbounded unless a maximum distance is set.
GaussianDenoise
¶
Bases: Operator
Gaussian smoother over the trailing two spatial axes.
Normalized convolution: nodata (fill / non-finite) pixels are excluded from both the numerator and the normalising weight, so they never smear into their neighbours, and hold the output fill. Non-spatial axes (e.g. bands) are not filtered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
float
|
Gaussian standard deviation in pixels. |
1.0
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
spatial_reach()
¶
MNF
¶
Bases: Operator
Minimum Noise Fraction transform (Green et al. 1988), with its inverse.
Wraps :func:~geoops.restore._src.array.fit_mnf. The noise
covariance Σ_N is estimated from horizontal shift differences
(Σ_N = Cov(z(i, j) − z(i, j + 1)) / 2, see
:func:~geoops.restore._src.array.shift_difference_noise_covariance);
the data are noise-whitened with Σ_N^(−1/2) (Cholesky) and the
whitened data are rotated onto their principal components. The
output carrier holds the scores, ordered by decreasing SNR, and
:meth:inverse maps scores back to band space with
x̂ = Σ_N·A_k·y + x̄ -- keeping the first n_components and
inverting is the classical MNF noise filter.
Fitted operator (see Fitted operators in the concepts guide):
:meth:fit learns the basis, :meth:transform projects any cube with
the same bands onto it and :meth:inverse reconstructs, neither
mutating the operator. Calling an unfitted operator fits the basis on
that first call (once, even under concurrent calls) and every later
call reuses it; call :meth:fit explicitly to choose the scene, e.g.
before parallel use. The basis is never part of get_config().
The covariance and noise covariance are estimated from valid pixels
only (a pixel invalid in any band is excluded, and so is any
neighbour pair touching it); invalid pixels hold NaN in the
returned scores, and pixels with a non-finite score hold the output
fill after :meth:inverse.
Inputs are (C, H, W) cubes or (T, C, H, W) stacks (one fit
over every frame's pixels; noise pairs never cross frames); the
scores keep the input layout with the band axis replaced by the
component axis ((K, H, W) / (T, K, H, W)). A 2-D (H, W)
map raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int | None
|
Number of components to keep. |
None
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
state_ |
dict[str, ndarray] | None
|
The fitted basis ( |
eigenvalues_ |
ndarray | None
|
The generalised eigenvalues |
snr_ |
ndarray | None
|
Per-component signal-to-noise ratio |
Examples:
>>> mnf = gz.restore.MNF(n_components=3).fit(scene)
>>> scores = mnf(scene)
>>> denoised = mnf.inverse(scores)
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
fit(gt)
¶
Learn the MNF basis from the valid pixels of gt.
Returns:
| Type | Description |
|---|---|
Self
|
This operator, for chaining. |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
inverse(gt)
¶
Reconstruct band space from MNF scores (x̂ = Σ_N·A_k·y + x̄).
With all components the reconstruction is exact; with fewer it removes the low-SNR components (the MNF noise filter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gt
|
GeoArray | ndarray
|
Scores as returned by :meth: |
required |
Returns:
| Type | Description |
|---|---|
GeoArray | ndarray
|
The reconstructed |
GeoArray | ndarray
|
pixels with a non-finite score hold the output fill. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the operator is not fitted or |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
transform(gt)
¶
Project gt onto the fitted MNF basis.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the operator is not fitted, |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
MedianDenoise
¶
Bases: Operator
Median filter over the trailing two spatial axes.
Robust to impulse noise (salt-and-pepper, hot pixels). Larger
window blurs sharper features. Nodata (fill / non-finite) pixels
are replaced by the median of the valid pixels before filtering and
hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
Side length of the median window in pixels. |
3
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
MomentMatching
¶
Bases: Operator
Destripe by matching every column's mean and std to a reference.
Convenience operator equivalent to
DestripeColumn(method="moment_matching", direction="column", window=...)
(same nodata handling): out[:, j] = (z[:, j] − μ_j)·σᵣ_j/σ_j + μᵣ_j
(Gadallah et al. 2000).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int | None
|
Number of neighbouring columns averaged into the
reference moments, or |
21
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
NLMeans
¶
Bases: Operator
Lightweight non-local-means-style denoiser.
Wraps :func:~geoops.restore._src.array.nl_means. This is a
dependency-light approximation of the canonical NL-means; for
production use prefer skimage.restoration.denoise_nl_means.
Nodata (fill / non-finite) pixels are excluded from the smoothing
and hold the output fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
Nominal patch (comparison-window) side length in pixels. |
5
|
search_radius
|
int
|
Nominal search-window radius in pixels. |
6
|
h
|
float
|
Range bandwidth in data units. |
0.1
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
OutlierMask
¶
Bases: Operator
Flag global outliers with a MAD or z-score threshold.
Wraps :func:~geoops.restore._src.array.outlier_mask and returns
a boolean carrier (True marks outliers). Outputs the result
as bool to keep the mask explicit. Nodata (fill / non-finite)
pixels are excluded from the statistics and reported as False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['mad', 'zscore']
|
|
'mad'
|
k
|
float
|
Threshold in scaled units. |
3.0
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
ReplaceOutliers
¶
Bases: Operator
Replace outliers with median, NaN, or nearest-neighbour interpolation.
Wraps :func:~geoops.restore._src.array.replace_outliers.
Nodata (fill / non-finite) pixels are excluded from the outlier
statistics and hold the output fill value (they are not filled).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['mad', 'zscore']
|
Outlier detector. See :class: |
'mad'
|
k
|
float
|
Threshold in scaled units. |
3.0
|
strategy
|
Literal['median', 'nan', 'interp']
|
|
'median'
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/restore/_src/operators.py
bilateral_denoise(arr, *, sigma_color=0.1, sigma_space=5.0)
¶
Edge-aware denoise using a range-weighted Gaussian approximation.
Computes a spatially smoothed estimate s of shape arr and
blends it with the original x using a per-pixel weight
:math:w = \exp(-\tfrac{1}{2} ((x - s) / \sigma_c)^2). Where
x is far from the local mean (edges, outliers), w is small
and the smoothed estimate is suppressed in favour of the
original, preserving edges. Where x is close to the local mean
(flat regions), w is near 1 and the original passes through —
the smoothing is therefore best thought of as an edge-aware
attenuator of the Gaussian estimate.
This is a single-pass approximation of a full bilateral filter (no per-pixel neighbourhood weighting). It is fast and dependency- light; for true bilateral filtering use scikit-image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
sigma_color
|
float
|
Range bandwidth (data units). Smaller values preserve more edges; larger values smooth more. |
0.1
|
sigma_space
|
float
|
Spatial bandwidth in pixels. |
5.0
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Denoised array with the same shape and NaN positions as |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
despeckle_frost(arr, *, window=7, damping=2.0)
¶
Apply the Frost (1982) adaptive exponential-kernel speckle filter.
Each output pixel is a normalised weighted mean of its
window × window neighbourhood with the exponentially
decaying kernel::
m(t) = exp(−K · Cᵥ² · |t|)
x̂ = Σₜ m(t)·z(t) / Σₜ m(t)
where K is damping, |t| is the Euclidean distance (in
pixels) from the centre pixel and Cᵥ² = σ_z² / z̄² is the local
squared coefficient of variation, computed over the same window.
On homogeneous areas Cᵥ² is small, the kernel is wide and the
filter approaches the box mean; at edges Cᵥ² is large, the
kernel narrows onto the centre pixel and the edge is preserved.
Where z̄ = 0 the kernel is the box mean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
window
|
int
|
Side length of the kernel window. Must be positive. |
7
|
damping
|
float
|
Damping factor |
2.0
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Smoothed array with the same shape and NaN positions as |
References
Frost, V. S., Stiles, J. A., Shanmugan, K. S., & Holtzman, J. C. (1982). A model for radar images and its application to adaptive digital filtering of multiplicative noise. IEEE TPAMI, 4(2), 157-166.
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
despeckle_lee(arr, *, window=7, cu=0.523)
¶
Apply the Lee (1980) local-statistics speckle filter.
Speckle model: z = x·v with x the unspeckled signal and v
unit-mean multiplicative noise of coefficient of variation
Cᵤ = σᵥ (cu). With the local mean z̄ and variance σ_z²
over a window × window neighbourhood, the model gives
(Lee 1980)::
σ_x² = max((σ_z² − Cᵤ²·z̄²) / (1 + Cᵤ²), 0)
k = σ_x² / (σ_x² + Cᵤ²·z̄²)
x̂ = z̄ + k·(z − z̄)
In terms of the local coefficient of variation Cᵢ = σ_z / z̄ the
gain is k = (Cᵢ² − Cᵤ²) / (Cᵢ² + Cᵤ⁴) clipped at 0, so
k ∈ [0, 1): on homogeneous speckle (Cᵢ ≤ Cᵤ) k = 0 and
the filter returns the local mean; at edges and point targets
(Cᵢ ≫ Cᵤ) k → 1 and the pixel passes through. Dropping the
O(Cᵤ⁴) term gives the familiar linearised k ≈ 1 − Cᵤ²/Cᵢ².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
window
|
int
|
Side length of the local window. Must be positive. |
7
|
cu
|
float
|
Noise coefficient of variation |
0.523
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Smoothed array with the same shape and NaN positions as |
References
Lee, J.-S. (1980). Digital image enhancement and noise filtering by use of local statistics. IEEE TPAMI, 2(2), 165-168.
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
despeckle_refined_lee(arr, *, window=7)
¶
Apply a Refined-Lee approximation.
The full Refined-Lee filter chooses one of eight directional
sub-windows per pixel before applying the Lee gain. This
dependency-light implementation skips the directional selection and
just calls :func:despeckle_lee with the default cu. It is
kept under a distinct name so pipelines can swap in a true Refined-
Lee later without renaming nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
window
|
int
|
Side length of the local window. Must be positive. |
7
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Smoothed array with the same shape and NaN positions as |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
destripe_column(arr, *, method='mean', direction='column', window=21)
¶
Remove row or column striping by matching per-line statistics.
For direction="column" (default) every column j is summarised over
its rows; direction="row" swaps the roles. Leading axes are independent
planes.
method="mean" / "median" remove a per-column offset::
out[:, j] = z[:, j] − (s_j − s̄)
where s_j is the column mean (median) and s̄ the mean (median)
of all s_j.
method="moment_matching" removes a per-column gain and offset
(Gadallah et al. 2000): each column is linearly rescaled so its mean
μ_j and standard deviation σ_j match a reference (μᵣ, σᵣ)::
out[:, j] = (z[:, j] − μ_j) · σᵣ_j / σ_j + μᵣ_j
With window=None the reference is global (μᵣ and σᵣ are
the averages of μ_j and σ_j over all columns); with an integer
window it is the moving average of μ_j / σ_j over the
window neighbouring columns, which keeps genuine cross-track
trends (e.g. illumination) while removing the detector-to-detector
stripes. Within-column detail is untouched apart from the per-column
linear map. A column with σ_j = 0 only has its offset matched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
method
|
Literal['mean', 'median', 'moment_matching']
|
|
'mean'
|
direction
|
Literal['column', 'row']
|
Striping direction ( |
'column'
|
window
|
int | None
|
Number of neighbouring columns (rows) averaged into the
moment-matching reference, or |
21
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Destriped array with the same shape and NaN positions as |
Float[ndarray, '*batch h w']
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
References
Gadallah, F. L., Csillag, F., & Smith, E. J. M. (2000). Destriping multisensor imagery with moment matching. International Journal of Remote Sensing, 21(12), 2505-2511.
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
gap_fill_biharmonic(arr)
¶
Fill NaNs by biharmonic inpainting.
Solves :math:\Delta^2 u = 0 on the missing pixels with the finite
pixels as Dirichlet values, through functax.project.fill_gaps
(the [interp] extra, same edge-repeat Laplacian as
:func:gap_fill_laplacian). Smoother across the mask boundary than the
harmonic fill: the gradient is continuous there too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Filled array with the same shape as |
Float[ndarray, '*batch h w']
|
finite pixels are preserved exactly. |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
gap_fill_idw(arr, *, power=2.0, radius=5)
¶
Fill NaNs with inverse-distance weighted finite neighbours.
For each NaN pixel p, takes all finite neighbours within
radius pixels (Euclidean) and replaces it with
:math:\hat{p} = \sum_i w_i x_i / \sum_i w_i where
:math:w_i = 1 / \max(d_i, \epsilon)^{\text{power}}. NaNs whose
neighbourhood is empty are left as NaN.
The weights come from one functax.interp.InverseDistance plan per
2-D plane (the [interp] extra), from the finite pixels to the gaps,
with k the number of pixels within radius so the neighbourhood is
the whole disc.
Powers >= 64 numerically converge to nearest-neighbour weights,
so the function short-circuits to :func:gap_fill_nearest in that case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
power
|
float
|
IDW exponent. |
2.0
|
radius
|
int
|
Maximum search radius in pixels. |
5
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Filled array with the same shape as |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
gap_fill_laplacian(arr, *, iterations=None)
¶
Fill NaNs by solving a discrete Laplace equation.
Solves :math:\Delta u = 0 on the missing pixels with the finite
pixels as Dirichlet values, through functax.project.fill_gaps
(the [interp] extra): the five-point Laplacian with edge-repeat
boundaries (the ghost pixel past the raster edge is the edge pixel), solved
by conjugate gradients to √ε. This is the limit the Jacobi sweeps of
earlier releases converged to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
iterations
|
int | None
|
Deprecated and ignored (the solve is exact); passing it warns. |
None
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Filled array with the same shape as |
Float[ndarray, '*batch h w']
|
finite pixels are preserved exactly. |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
gap_fill_nearest(arr, *, max_distance=None)
¶
Fill NaNs from the nearest finite neighbour.
Reads each gap from its nearest finite pixel through a one-neighbour
functax.interp.InverseDistance plan per 2-D plane (the [interp]
extra). Where several finite pixels are equally near, the plan's k-d
tree picks one of them. Pixels whose nearest finite neighbour is
farther than max_distance (when given) are left as NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
max_distance
|
int | None
|
Optional maximum Euclidean fill radius in pixels.
|
None
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Filled array with the same shape as |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
gaussian_denoise(arr, *, sigma=1.0)
¶
Gaussian smooth over the trailing two (spatial) axes.
NaN-aware: missing pixels are excluded from both numerator and
weight (Nadaraya-Watson style normalisation), then re-stamped onto
the output. Non-spatial axes (e.g. bands) are filtered
independently with sigma=0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
sigma
|
float
|
Gaussian standard deviation in pixels. |
1.0
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Smoothed array with the same shape and NaN positions as |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
median_denoise(arr, *, window=3)
¶
Median smooth over the trailing two (spatial) axes.
NaNs are temporarily replaced with the global nanmedian so
SciPy's median filter is well-defined, then re-stamped on the
output. Edge pixels use mode="nearest" (the edge pixel is
repeated outwards, not reflected).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
window
|
int
|
Side length of the median window. Must be positive. |
3
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Smoothed array with the same shape and NaN positions as |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
nl_means(arr, *, window=5, search_radius=6, h=0.1)
¶
Lightweight non-local-means-style denoiser.
True non-local-means averages each pixel with similarly-patterned
patches elsewhere in the image, which is expensive and adds
scikit-image as a dependency. This implementation is a
dependency-light approximation: it computes a wide Gaussian
smoothing estimate whose effective radius is set by
(search_radius + window) / 6, then blends it with the
original using the same range-weighted scheme as
:func:bilateral_denoise with bandwidth h.
Use this only when scikit-image is unavailable; for production
NL-means, prefer skimage.restoration.denoise_nl_means.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Array of shape |
required |
window
|
int
|
Nominal patch side length (pixels). |
5
|
search_radius
|
int
|
Nominal search-window radius (pixels). |
6
|
h
|
float
|
Range bandwidth (data units). |
0.1
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Denoised array with the same shape and NaN positions as |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
outlier_mask(arr, *, method='mad', k=3.0)
¶
Flag robust global outliers.
method="mad" (default) uses the median + median-absolute-
deviation; "zscore" uses the mean + standard deviation. The MAD
is scaled by 1 / Phi^{-1}(0.75) so it estimates the same scale as
the standard deviation under a Gaussian model. Returns a boolean
array where True marks outliers.
When the estimated scale is zero (constant data) the mask flags any pixel that differs from the centre, which is consistent with "anything that breaks the constant pattern is an outlier". When the scale is non-finite (all-NaN input) returns an all-False mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*dims']
|
Input array of any shape. Statistics are global (whole array), not windowed. |
required |
method
|
Literal['mad', 'zscore']
|
|
'mad'
|
k
|
float
|
Threshold in scaled units (approximately standard deviations). |
3.0
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*dims']
|
Boolean array of the same shape; |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
pca_denoise(arr, *, n_components, axis=-3)
¶
Reconstruct an array from its top PCA components along axis.
Convenience composition of :func:fit_pca and :func:inverse_pca.
Keeping fewer components than bands suppresses band-uncorrelated
noise while preserving the dominant spectral structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*dims']
|
Array with a band axis at position |
required |
n_components
|
int
|
Number of principal components to keep. Must be between 1 and the number of bands. |
required |
axis
|
int
|
Position of the band axis. Defaults to |
-3
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*dims']
|
Reconstructed array with the same shape and NaN positions as |
Float[ndarray, '*dims']
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/restore/_src/array.py
replace_outliers(arr, *, method='mad', k=3.0, strategy='median')
¶
Replace detected outliers with a scalar or nearest-neighbour fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Num[ndarray, '*batch h w']
|
Input array. |
required |
method
|
Literal['mad', 'zscore']
|
Outlier-detection strategy. See :func: |
'mad'
|
k
|
float
|
Outlier threshold in scaled units. |
3.0
|
strategy
|
Literal['median', 'nan', 'interp']
|
|
'median'
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*batch h w']
|
Array of the same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |