classify_pixels: Classifies the pixels of an image

Description Usage Arguments Details Value See Also Examples

View source: R/classify_pixels.R

Description

Classifies the pixels represented in an object of class transformed_image using the rules contained in a list of objects of class pixel_cat.

Usage

1
classify_pixels(image_prop, ..., unclassed_colour = "black", verbose = TRUE)

Arguments

image_prop

an array containing the image. It must be an object produced with function read_image().

...

a list of objects of class pixel_cat containing the classification rules.

unclassed_colour

a character string setting the colour to be assigned to unclassified pixels. Defaults to "black".

verbose

a logical value. When TRUE (default) the function prints some statistics about the classification.

Details

This function generates a set of incidence matrices indicating whether a pixel belongs to a pixel category or not. An additional matrix identifies the pixels that do not belong to the defined categories, i e unclassed pixels. Depending on how the rules were defined, it can be void or contain pixels, but it is always present and named unclassified.

To create the incidence matrices for each category, a matrix for each rule is created and then combined with the matrices of the other using the and operator.

When a set of subcategories is used, the procedure is the same for each subcategory and then the matrices of the subcategories are combined again, this time using the or operator. See the help for define_subcat for more details.

unclassed_colour can be specified in any form understood by grDevices::col2grb.

Value

Returns an object of class classified_image, which is a list containing nested lists. Each first-level element corresponds to one of the pixel categories and its name is the category name. They contains the second-level list, which have the following elements:

See Also

define_cat, col2rgb.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# The series of steps to classify a image supplied in the package

yellow <- "#ffcd0eff"
blue <- "#5536ffff"

ivy_oak_rgb <- read_image(system.file("extdata", "IvyOak400x300.JPG",
                          package = "pixelclasser"))

rule_01 <- define_rule("rule_01", "g", "b",
                       list(c(0.345, 1/3), c(0.40, 0.10)), comp_op = "<")
rule_02 <- define_rule("rule_02", "g", "b",
                       list(c(0.345, 1/3), c(0.40, 0.10)), comp_op = ">=")

cat_dead_leaves <- define_cat("dead_leaves", blue, rule_01)
cat_living_leaves <- define_cat("living_leaves", yellow, rule_02)

ivy_oak_classified <- classify_pixels(ivy_oak_rgb, cat_dead_leaves,
                        cat_living_leaves)

ropensci/pixelclasser documentation built on Feb. 25, 2021, 2:08 p.m.