Learn R Programming

videoplayR (version 0.3.1)

thresholding: Convert image to binary image

Description

This function converts an image (rgb, grayscale or numeric) to binary by applying a thresholding function to it. 3-channels images (rgb and numeric) are first converted to 1-channel images (grayscale or numeric) prior to applying the thresholding function.

Usage

thresholding(image, thres, type)

Arguments

image
A vpImage object to convert to a binary image.
thres
The threshold value to separate the pixels of the image in two groups.
type
The type of thresholding function to apply to the image. If set to "binary", then the pixels above thres are replaced with ones and those below are replaced with zeros. If set to "inverted", then the pixels above thres are replaced with zeros and those below are replaced with ones.

Value

This function returns a vpImage object.

Details

The vpImage object created by the thresholding function is not a persistent object, but a pointer to a C++ object that cannot be saved for reuse in a different session.

See Also

vpImage

Examples

Run this code
filename <- system.file("sample_img/SampleVideo_1080x720_5mb.png", package = "videoplayR")
img <- readImg(filename)
imshow(img)
bin <- thresholding(img, 128, "binary")
imshow(bin)
inv <- thresholding(img, 128, "inverted")
imshow(inv)

Run the code above in your browser using DataLab