MyNixOS website logo
Description

Apply Unsupervised Segmentation Algorithms from 'OTB'.

Apply unsupervised segmentation algorithms included in 'Orfeo ToolBox' software (<https://www.orfeo-toolbox.org/>), such as mean shift or watershed segmentation.

OTBsegm OTBsegm website

CRANstatus Lifecycle:experimental Codecov testcoverage License: GPLv3 Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped.

OTBsegm is an R package that provides a user-friendly interface to the unsupervised image segmentation algorithms available in Orfeo ToolBox (OTB), a powerful open-source library for remote sensing image processing. OTBsegm is built on top of link2GI R package, providing easy access to image segmentation algorithms.

To use {OTBsegm}, you must first install OTB on your machine. Once OTB is installed and properly linked through {link2GI} (see examples), this package allows you to easily integrate OTB’s segmentation algorithms into your workflows.

Installation

You can install the development version of OTBsegm from GitHub with:

# install.packages("pak")
pak::pak("Cidree/OTBsegm")

Example

We will see how to segment an image included in the package:

## load packages
library(link2GI)
library(OTBsegm)
library(terra)
#> Warning: package 'terra' was built under R version 4.4.3
#> terra 1.8.29

## load image
image_sr <- rast(system.file("raster/pnoa.tiff", package = "OTBsegm"))

## visualize
plotRGB(image_sr)

The image is a 500x500 meters RGB tile, with a spatial resolution of 15 cm in Galicia, Spain. The meanshift algorithm has the next important arguments:

  • spatialr: spatial radius of the neighborhood

  • ranger: range radius defining the radius (expressed in radiometry unit) in the multispectral space

  • minsize: minimum size of a region (in pixel unit) in segmentation. Smaller clusters will be merged to the neighboring cluster with the closest radiometry. If set to 0 no pruning is done. The image’s resolution is 1.2 m, therefore, a value of minsize = 10 means that the smallest segment will be $10 * 1.2^2 = 14.4 m^2$.

In order to use the algorithms, we need to link our OTB installation using {link2GI}:

otblink <- link2GI::linkOTB(searchLocation = "C:/OTB/")

Once we are connected, we can apply the segmentation algorithm and visualize the results:

results_ms_sf <- segm_meanshift(
    image    = image_sr,
    otb      = otblink,
    spatialr = 5,
    ranger   = 25,
    maxiter  = 10,
    minsize  = 10
)
#> Reading layer `filecfc6b37181f' from data source 
#>   `C:\Users\User\AppData\Local\Temp\RtmpAjZLFx\filecfc6b37181f.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 811 features and 1 field
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 621000 ymin: 4708385 xmax: 621300 ymax: 4708685
#> Projected CRS: ETRS89 / UTM zone 29N
plotRGB(image_sr)
plot(sf::st_geometry(results_ms_sf), add = TRUE)
Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows