pixThresholdToBinary: Threshold the Pixels in a Pix Image

View source: R/leptonica.R

pixThresholdToBinaryR Documentation

Threshold the Pixels in a Pix Image

Description

These functions set a subset of the values in a Pix-class object to a single specific value. We can set all pixels with a value greater than threshold to a given value, or all pixels with a valye less than the threshold to a given value.

If newValue is greater than or equal to threshold, then pixels with a current value above threshold will be set to newValue and all other pixels will remain unchanged.

Alternatively, if newValue is less than or equal to threshold, all pixels with a current value less than threshold will be set to newValue and the pixels with a value greater than or equal to threshold will remain unchanged.

For pixThresholdToBinary, pixels with a value less than threshold will be set to 1 (corresponding to white) and pixels with a value greater than or equal to threshold will be set to 0 (corresponding to black).

Usage

pixThresholdToBinary(pix, threshold, dims = GetImageDims(pix))
pixThresholdToValue(pix, threshold, newValue, target = NULL) 

Arguments

pix

a Pix-class image object

threshold

the threshold value which identifies which pixels to change

dims

an integer vector providing the dimensions of the image.

newValue

the new value for the pixels to take

target

either a Pix-class object or NULL. If a Pix is specified, this is used to store the answer. Otherwise, a new Pix is created and returned.

Value

These functions return a new Pix-class object.

Author(s)

Duncan Temple Lang

See Also

pixRead GetInputImage pixAnd

Examples

f = system.file("images", "SMITHBURN_1952_p3.png", package = "Rtesseract")
p1 = pixRead(f)
p1 = pixConvertTo8(p1)
bin = pixThresholdToBinary(p1, 150)
angle = pixFindSkew(bin)

duncantl/Rtesseract documentation built on Sept. 8, 2024, 8:38 a.m.