Collect seed points interactively by clicking on the image. Each left-click
adds a new seed; pressing ESC ends the session. After each click,
SNIC segmentation is recomputed and plotted for visual feedback. This is
intended for exploratory and fine-tuning workflows, where automatic seeding
may not be ideal.
Arguments
- x
A
SpatRasterobject with a valid spatial reference and extent. Mouse clicks are interpreted in map coordinates.- seeds
Optional existing seed set to display and extend. If pixel coordinates are supplied, they are internally converted. If
NULL, the seed set is initialized empty and populated interactively.- ...
Arguments forwarded to
snic_plotfor display control. These may includeband,r,g,b,stretch,seeds_plot_args, orseg_plot_args.- snic_args
A list of arguments passed to
snic, such ascompactness.- snic_plot_args
A list of display modifiers forwarded to
snic_plotwhen rendering the preview.
Value
A two-column data frame of seed coordinates. If x lacks a CRS the
result is always pixel indices (r, c). When x has a CRS:
If
seedswere supplied, their coordinate system is preserved in the output.Otherwise the result is expressed as
(lat, lon)inEPSG:4326.
The output can be passed directly to snic.
Details
After each new seed is placed interactively, segmentation is recomputed to provide immediate feedback on how the seed placement affects clustering.
Examples
if (interactive() && requireNamespace("terra", quietly = TRUE)) {
tiff_dir <- system.file("demo-geotiff",
package = "snic",
mustWork = TRUE
)
files <- file.path(
tiff_dir,
c(
"S2_20LMR_B02_20220630.tif",
"S2_20LMR_B04_20220630.tif",
"S2_20LMR_B08_20220630.tif",
"S2_20LMR_B12_20220630.tif"
)
)
s2 <- terra::aggregate(terra::rast(files), fact = 8)
seeds <- snic_grid_manual(
s2,
snic_args = list(compactness = 0.1),
snic_plot_args = list(r = 4, g = 3, b = 1)
)
seg <- snic(s2, seeds, compactness = 0.1)
snic_plot(
s2,
r = 4, g = 3, b = 1,
stretch = "lin",
seeds = seeds,
seg = seg
)
}