improfile: Pixel Values Along a Line Segment

View source: R/shape.R

improfileR Documentation

Pixel Values Along a Line Segment

Description

improfile finds all pixels intersected by a line segment and returns their coordinates and color values.

Usage

improfile(image, xi, yi, connectivity = 8, left_to_right = FALSE)

Arguments

image

An Image object.

xi, yi

Two-element vectors containing the x and y coordinates of the start and end points of a line segment. The points can lie outside of the image boundaries but then the line will be clipped on the image boundaries.

connectivity

The connectivity neighborhood to decide whether 2 pixels are contiguous. This parameter can take two values:

  • 4: the neighborhood of a pixel are the four pixels located above (north), below (south), to the left (west) and right (east) of the pixel.

  • 8 (the default): the neighborhood of a pixel includes the four 4-neighbors and the four pixels along the diagonal directions (northeast, northwest, southeast, and southwest).

left_to_right

If 'TRUE', the line segment is traversed from the leftmost endpoint to the rightmost endpoint, regardless of the order in which they are specified in xi and yi. Otherwise (the default), the line is traversed in the order in which the points are specified in xi and yi.

Value

A matrix in which the first two columns indicate the coordinates of the points traversed by the line segment, and the other columns indicate the color values at each location.

Author(s)

Simon Garnier, garnier@njit.edu

Examples

dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
improfile(dots, c(1, ncol(dots)), c(nrow(dots) / 2, nrow(dots) / 2))


swarm-lab/Rvision documentation built on Feb. 7, 2024, 4:59 a.m.