classify_pixels {pixelclasser} | R Documentation |
Classifies the pixels of an image
Description
Classifies the pixels represented in an object of class
"pixel_transformed_image"
using the rules contained in a list of
objects of class "pixel_category"
.
Usage
classify_pixels(image_prop, ..., unclassed_colour = "black", verbose = TRUE)
is.classified_image(x)
## S3 method for class 'pixel_classified_image'
summary(object, ...)
Arguments
image_prop |
an object of class |
... |
in |
unclassed_colour |
a character string defining the colour of the
unclassified pixels. Defaults to |
verbose |
a logical value. When |
x |
the R object being tested. |
object |
an object of class |
Details
This function uses the rules contained in "pixel_category"
objects to create a set of incidence matrices indicating whether a pixel
belongs to a pixel category or not.
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. An additional matrix identifies the pixels that do not
belong to the defined categories, i.e. unclassed pixels. It is always
present and named unclassified
even in the case that all pixels were
assigned to some class.
When a category is divided in a set of subcategories the pixels are
classfied in subcategories as explained in the previous paragraph, and then
the matrices of the subcategories are combined again, this time using the
or
operator. See "pixel_subcategory"
for more details.
unclassed_colour
can be specified in any form understood by
grDevices::col2grb
.
Value
Returns an object of class "pixel_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:
-
colour
: a matrix defining a colour to paint the pixels in the classified image. Inherited from the"pixel_class"
object defining the class. -
incid_mat
: a logical matrix whereTRUE
values indicate that the pixel belongs to this pixel category.
See Also
Examples
# These are the steps to classify an example image supplied in the package
yellow <- "#ffcd0eff"
blue <- "#5536ffff"
ivy_oak_rgb <- read_image(system.file("extdata", "IvyOak400x300.JPG",
package = "pixelclasser"))
rule_01 <- pixel_rule("rule_01", "g", "b",
list(c(0.345, 1/3), c(0.40, 0.10)), comp_op = "<")
rule_02 <- pixel_rule("rule_02", "g", "b",
list(c(0.345, 1/3), c(0.40, 0.10)), comp_op = ">=")
cat_dead_leaves <- pixel_category("dead_leaves", blue, rule_01)
cat_living_leaves <- pixel_category("living_leaves", yellow, rule_02)
ivy_oak_classified <- classify_pixels(ivy_oak_rgb, cat_dead_leaves,
cat_living_leaves)