Learn R Programming

SPUTNIK (version 1.4.2)

removeSmallObjects,ms.image-method: Remove binary ROI objects smaller than user-defined number of pixels

Description

Remove binary ROI objects smaller than user-defined number of pixels

Usage

# S4 method for ms.image
removeSmallObjects(object, threshold = 5, border = 3)

Value

ms.image-class object after filtering.

Arguments

object

ms.image-class object. See msImage.

threshold

numeric. Smallest number of connected pixels.

border

numeric (default = 3). Size of the empty border to add before detecting the connected objects. The border is removed at the end of the process. If `border = 0`, no border is added.

Examples

Run this code
library(SPUTNIK)

fakeBinImage <- matrix(0, 100, 100)
fakeBinImage[sample(prod(dim(fakeBinImage)), 2000)] <- 1

fakeBinMsImage <- msImage(values = fakeBinImage, name = "ROI", scale = FALSE)

# Remove the objects with a number of connected pixels smaller than 5
fakeBinMsImage <- removeSmallObjects(fakeBinMsImage, threshold = 5)

Run the code above in your browser using DataLab