Learn R Programming

pliman (version 3.1.0)

image_label: Label Connected Components in a Binary Image

Description

This function labels connected components in a binary image while allowing for a specified maximum gap between pixels to still be considered part of the same object.

Usage

image_label(img, max_gap = 0)

Value

An object of class Image (from the EBImage package), where each connected component is assigned a unique integer label.

Arguments

img

A binary image matrix where 1 represents foreground pixels and 0 represents background pixels. This should be compatible with the EBImage package.

max_gap

An integer specifying the maximum allowable gap (in pixels) between connected components to be considered as part of the same object. Default is 1.

Examples

Run this code
if(interactive()){
library(pliman)
img <- matrix(c(
  1, 1, 0, 0, 0, 1, 1, 1, 0,
  0, 0, 0, 0, 0, 1, 0, 0, 0,
  1, 1, 0, 0, 1, 1, 1, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 1
), nrow = 4, byrow = TRUE)

image_label(img, max_gap = 1)
image_label(img, max_gap = 2)
image_label(img, max_gap = 3)
}

Run the code above in your browser using DataLab