| patch | R Documentation |
Get the median (or mean or user-defined function) colour value of a specified patch of pixels on an image. This is useful for matching background colours.
patch(
stimuli,
width = 10,
height = 10,
x_off = 0,
y_off = 0,
color = c("hex", "rgb"),
func = stats::median
)
stimuli |
list of stimuli |
width, height |
dimensions of the patch in pixels, if <=1, interpreted as proportions of width or height |
x_off, y_off |
offset in pixels or proportion (<1) |
color |
The type of color to return (hex, rgb) |
func |
The function to apply to an array of L*ab color values to determine the central colour (defaults to median, but mean, min, or max can also be useful) |
The colour values of each pixel in the patch are converted to CIE-Lab values before using the func to calculate the central tendency of the L (lightness), a (red-green axis) and b (blue-yellow axis); see col2lab() and lab2rgb() for more details.
This excludes transparent pixels, and returns "transparent" if all pixels in the patch are transparent.
a vector of hex or rgba color values
stimuli <- demo_stim()
# get colour from the upper left corder
patch(stimuli)
# get median colour from centre .1 width pixels
patch(stimuli, width = .1, height = .1,
x_off = .45, y_off = .45)
# get mean rgb colour from full image
patch(stimuli, width = 1, height = 1,
color = "rgb", func = mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.