countPixelsFilter: Filter based on the minimum number of connected pixels in the...

View source: R/filter_count.R

countPixelsFilterR Documentation

Filter based on the minimum number of connected pixels in the ROI.

Description

countPixelsFilter selects peaks which signals are localized in regions consisting of a minimum number of connected pixels in the ROI.

Usage

countPixelsFilter(
  msiData,
  roiImage,
  minNumPixels = 9,
  smoothPeakImage = FALSE,
  smoothSigma = 2,
  closePeakImage = FALSE,
  closeKernSize = 5,
  aggressive = 0,
  verbose = TRUE
)

Arguments

msiData

msi.dataset-class object. See msiDataset.

roiImage

ms.image-class object representing the ROI mask. See msImage.

minNumPixels

integer (default = 9). Smallest number of connected pixels used to select a peak.

smoothPeakImage

logical (default = FALSE). Whether the peak images should be smoothed before determining the connected components.

smoothSigma

numeric (default = 2). Standard deviation of the smoothing Gaussian kernel.

closePeakImage

logical (default = FALSE). Whether morphological closing should be applied to the binary peak images.

closeKernSize

numeric (default = 5). Kernel size for the morphological closing operation. Kernel shape is fixed to diamond.

aggressive

integer (default = 0). Defines the level of aggressiveness of the filter. See 'Details' section.

verbose

logical (default = TRUE). Additional output text.

Details

Count filter tries to determine and remove peaks which signal is scattered in a region unrelated with the expected ROI. A minimum number of connected pixels in the ROI is used to trigger the filter. This value should be carefully set equal to the geometrical size of the smallest expected informative sub-region. Each peak image is binarized using Otsu's thresholding and the connected components are extracted. The filter selects those peaks that show, within the ROI, at least one connected component of size larger or equal to minNumPixels. The level of aggressiveness, associated with increasing values of the parameter aggressive, determines whether the size of the connected components within the ROI should be compared with that of the connected components localized outside the ROI. If aggressive = 0, no comparison is performed. If aggressive = 1, the filter checks whether the max size of the connected components localized outside the ROI is smaller or equal to the maximum size of the connected components inside the ROI. If aggressive = 2, a stricter filter checks whether the maximum size of the connected components localized outside the ROI is smaller than minNumPixels. Different aggressiveness levels can produce completely different results, depending on the nature of the analyzed dataset.

Value

peak.filter object. See applyPeaksFilter-msi.dataset-method.

Author(s)

Paolo Inglese p.inglese14@imperial.ac.uk

See Also

applyPeaksFilter

Examples

## Load package
library("SPUTNIK")

## Mass spectrometry intensity matrix
X <- matrix(rnorm(16000), 400, 40)
X[X < 0] <- 0

## Print original dimensions
print(dim(X))

## m/z vector
mzVector <- seq(600, 900, by = (900 - 600) / 39)

## Read the image size
imSize <- c(20, 20)

## Construct the ms.dataset object
msiX <- msiDataset(X, mzVector, imSize[1], imSize[2])

## Extract the ROI using k-means

refImg <- refImageContinuous(msiX, method = "sum")
roiImg <- refImageBinaryOtsu(refImg)

## Perform count pixels filtering
count.sel <- countPixelsFilter(
  msiData = msiX, roiImage = roiImg,
  minNumPixels = 4, aggressive = 1
)

## Apply the filter
msiX <- applyPeaksFilter(msiX, count.sel)

## Print new dimensions
print(dim(getIntensityMat(msiX)))

SPUTNIK documentation built on Nov. 24, 2022, 5:06 p.m.