Visualise a mini-batch of image chips, masks, distance-to-boundary grids, and the resulting edge-weight surface for a DataLoader that supplies distance grids.
Usage
viewDist(
dataLoader,
nCols = 3,
r = 1,
g = 2,
b = 3,
cCodes,
cNames,
cColors,
edgeMode = "gaussian",
distThreshold = 10,
minWght = 0.5,
maxWght = 1,
prioritizeEdge = TRUE,
padding = 10
)Arguments
- dataLoader
Instantiated DataLoader created with
torch::dataloader(). The batch must contain named elementsimage,mask, anddist.- nCols
Number of chip columns in each image grid. Default is 3.
- r
Index of the image channel mapped to the red display channel. Default is 1. For single-band imagery, assign the same index to
r,g, andb.- g
Index of the image channel mapped to the green display channel. Default is 2.
- b
Index of the image channel mapped to the blue display channel. Default is 3.
- cCodes
Integer class codes as a vector, one per class.
- cNames
Character vector of class names, in the same order as
cCodes.- cColors
Character vector of display colours for the mask panel, in the same order as
cCodes.- edgeMode
Character string specifying how distances are converted to weights. One of
"threshold","linear", or"gaussian"(default). Must match theedgeModeused indefineUnifiedFocalLoss.- distThreshold
Positive numeric. The distance value (in the same units as the distance raster) that defines the boundary of the high-weight zone. Default is 10.
- minWght
Numeric. Minimum per-pixel weight. Must be less than
maxWght. Default is 0.5.- maxWght
Numeric. Maximum per-pixel weight. Must be greater than
minWght. Default is 1.0.- prioritizeEdge
Logical. When
TRUE(default), pixels near class boundaries (small distance) receivemaxWghtand pixels far from boundaries receiveminWght. WhenFALSE, the relationship is reversed.- padding
Integer. Number of pixels of padding between chips in the grid. Default is 10.
Details
Plots four panels stacked vertically:
RGB image chips arranged in a grid.
Corresponding class masks.
Distance-to-class-boundary grids produced by
makeBoundaryDistance.The per-pixel edge-weight surface derived from those distances, computed with the same formula used by
defineUnifiedFocalLosswhenuseEdgeDist = TRUE.
The weight surface mirrors the three modes available in defineUnifiedFocalLoss:
"threshold"Pixels within
distThresholdreceive one weight (maxWghtwhenprioritizeEdge = TRUE); all others receive the opposite weight."linear"Weight decreases linearly from
maxWghtat distance 0 tominWghtatdistThreshold(whenprioritizeEdge = TRUE), clamped beyond the threshold."gaussian"Weight follows a Gaussian curve centred at distance 0 with sigma = distThreshold / 3, so the weight equals approximately
minWghtat the threshold and is clamped tominWghtbeyond it (whenprioritizeEdge = TRUE).
The DataLoader must return batches with three named elements: image,
mask, and dist. The dist element should be a tensor of
shape (N, 1, H, W) containing the per-pixel distances produced by
makeBoundaryDistance.
Examples
if (FALSE) { # \dontrun{
viewDist(
dataLoader = trainDL,
nCols = 4,
r = 1, g = 2, b = 3,
cCodes = c(1, 2, 3, 4, 5),
cNames = c("Background", "Forest", "Water", "Urban", "Agriculture"),
cColors = c("gray", "darkgreen", "blue", "red", "yellow"),
edgeMode = "gaussian",
distThreshold = 10,
minWght = 0.4,
maxWght = 1.0,
prioritizeEdge = TRUE
)
} # }
