Context features

Context features describe the neighbourhood of each label pixel: edges, local diversity, probability confidence, local class support, purity and optional class-pair relations.

Minimum inputs

InputNeeded forNotes
Hard label rasterEdge risk, diversity, hard-label class contextUses the selected NoData/background value.
Probability stackEntropy, margin, soft class contextOne band per class; stack is normalized internally.
Class schema CSVOptionalGives readable band names and class order.

Important controls

ControlEffect
Radius and window shapeDefine the local neighbourhood N_R(x).
Feature setSelects edge, diversity, entropy and margin.
Write class/local/pairwise contextCreates optional multi-band context stacks.
Include self-pairs / max pairwise bandsControls class-pair stack size.

Core calculations

edge(x) = 1 if any 4-neighbour has a different valid class; otherwise 0
edge-riskR(x) = dilate(edge, R)

Edge risk: marks class boundaries and their neighbourhood. It helps identify pixels where a crisp class label is spatially fragile.

diversityR(x) = |{zNR(x) : y(z)≠y(x)}| / |{zNR(x) : y(z) valid}|

Diversity: fraction of valid neighbours that differ from the centre class. High diversity means mixed local context.

H(x) = −∑c pc(x) · ln(pc(x)) / ln(C)

Entropy: normalized probability uncertainty. It requires a probability stack and is 0 for a confident single class.

margin(x) = p(1)(x) − p(2)(x)

Margin: distance between the strongest and second-strongest class probability. Low margin indicates ambiguity.

supportc,R(x) = meanz∈NR(x) pc(z)
supportc,R(x) ← supportc,R(x) / ∑j supportj,R(x)

Class support: local average support for class c, normalized over classes where support exists.

purityR(x) = maxc supportc,R(x)

Local purity: dominance of the strongest class in the neighbourhood.

pairi,j,R(x) = pi(x) · supportj,R(x)

Pairwise context: describes how centre-class support i interacts with neighbourhood support j. Self-pairs can be included or excluded.

Main outputs

OutputMeaning
Edge riskByte 0/100 raster, NoData 255.
Diversity, entropy, marginFloat32 0..1 rasters, NoData -9999.
Class support / local purity / pairwise contextOptional multi-band context stacks for later modelling or supervision.
Report JSONParameters, skipped outputs, band counts and paths.

Entropy and margin require a probability stack. Skipped outputs are reported and leave empty result paths.