| Title: | Image Filters with 'OpenCV' |
|---|---|
| Description: | Offers image filters wrapping 'OpenCV' <https://opencv.org/>, ported from <https://github.com/5PB-3-4/AviUtl_OpenCV_Scripts>. |
| Authors: | Akiru Kato [aut, cre], Jeroen Ooms [cph], Rui. [cph] (Author of ray-cast/lut) |
| Maintainer: | Akiru Kato <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 26.05.24 |
| Built: | 2026-05-28 18:14:02 UTC |
| Source: | https://github.com/paithiov909/aznyan |
Applies a bilateral filter to a nativeRaster image.
This edge-preserving smoothing technique reduces noise while retaining sharp boundaries by considering both spatial distance and color similarity.
bilateral_filter( nr, d = 5, sigmacolor = 1, sigmaspace = 1, border = c(3, 4, 0, 1, 2), alphasync = FALSE )bilateral_filter( nr, d = 5, sigmacolor = 1, sigmaspace = 1, border = c(3, 4, 0, 1, 2), alphasync = FALSE )
nr |
A |
d |
An integer scalar specifying the diameter of the pixel neighborhood used for filtering. If set to a non-positive value, OpenCV computes the diameter from the sigmas. |
sigmacolor |
A numeric scalar giving the filter sigma in color space. Larger values allow blending of pixels with greater color differences. |
sigmaspace |
A numeric scalar giving the filter sigma in coordinate space. Larger values increase the spatial extent of smoothing. |
border |
An integer scalar specifying the border-handling mode.
One of |
alphasync |
A logical scalar.
If |
border corresponds to the OpenCV extrapolation types:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_WRAP
cv::BORDER_REFLECT_101
A nativeRaster object.
Blends two nativeRaster objects with the specified blend mode.
blend_alpha(src, dst) blend_darken(src, dst) blend_multiply(src, dst) blend_colorburn(src, dst) blend_lighten(src, dst) blend_screen(src, dst) blend_add(src, dst) blend_colordodge(src, dst) blend_hardlight(src, dst) blend_softlight(src, dst) blend_overlay(src, dst) blend_hardmix(src, dst) blend_linearlight(src, dst) blend_vividlight(src, dst) blend_pinlight(src, dst) blend_average(src, dst) blend_exclusion(src, dst) blend_difference(src, dst) blend_divide(src, dst) blend_subtract(src, dst) blend_luminosity(src, dst) blend_ghosting(src, dst)blend_alpha(src, dst) blend_darken(src, dst) blend_multiply(src, dst) blend_colorburn(src, dst) blend_lighten(src, dst) blend_screen(src, dst) blend_add(src, dst) blend_colordodge(src, dst) blend_hardlight(src, dst) blend_softlight(src, dst) blend_overlay(src, dst) blend_hardmix(src, dst) blend_linearlight(src, dst) blend_vividlight(src, dst) blend_pinlight(src, dst) blend_average(src, dst) blend_exclusion(src, dst) blend_difference(src, dst) blend_divide(src, dst) blend_subtract(src, dst) blend_luminosity(src, dst) blend_ghosting(src, dst)
src, dst
|
A |
A nativeRaster object.
Blue noise pattern of size 64x64
generated with ambient::noise_blue(c(64, 64)).
Range: [0, 1]
blue_noise_64x64blue_noise_64x64
An object of class matrix (inherits from array) with 64 rows and 64 columns.
Blur filters
median_blur(nr, ksize = 1) box_blur( nr, box_w = 1, box_h = box_w, normalize = TRUE, border = c(3, 4, 0, 1, 2) ) gaussian_blur( nr, box_w = 1, box_h = box_w, sigma_x = 0, sigma_y = sigma_x, border = c(3, 4, 0, 1, 2) )median_blur(nr, ksize = 1) box_blur( nr, box_w = 1, box_h = box_w, normalize = TRUE, border = c(3, 4, 0, 1, 2) ) gaussian_blur( nr, box_w = 1, box_h = box_w, sigma_x = 0, sigma_y = sigma_x, border = c(3, 4, 0, 1, 2) )
nr |
A |
ksize |
An integer scalar specifying the kernel size.
The actual kernel size becomes |
box_w |
An integer scalar controlling the half-size of the kernel in
the horizontal direction. The actual kernel width becomes |
box_h |
An integer scalar controlling the half-size of the kernel in
the vertical direction. Defaults to |
normalize |
A logical scalar
specifying whether the kernel is normalized by its area or not.
Defaults to |
border |
An integer scalar specifying the border-handling mode.
One of |
sigma_x, sigma_y
|
A numeric scalar giving the standard deviation of the
Gaussian kernel along the x-axis. A value of |
border corresponds to the OpenCV extrapolation types:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_REFLECT_101
cv::BORDER_ISOLATED
A nativeRaster object.
Reconstructs a low-frequency approximation of an image using a BlurHash-like discrete cosine transform (DCT) basis. The image is first converted to linear RGB, projected onto a grid of cosine components, and then reconstructed back into an sRGB image using only the specified number of horizontal and vertical components. This produces a smooth, compressed representation capturing the coarse structure and color of the input.
blurhash(nr, x_comps = 6, y_comps = 6)blurhash(nr, x_comps = 6, y_comps = 6)
nr |
A |
x_comps |
An integer scalar specifying the number of horizontal DCT
components to use.
Must be greater than |
y_comps |
An integer scalar specifying the number of vertical DCT
components to use.
Must be greater than |
A nativeRaster object.
Applies the Canny edge detector to a nativeRaster image.
The filter can operate either on a grayscale conversion or by aggregating edges detected independently from each RGB channel.
The result is returned as a 3-channel binary edge map, with optional alpha masking.
canny_filter( nr, asize = 2, balp = TRUE, use_rgb = TRUE, thres1 = 100, thres2 = 200, grad = TRUE )canny_filter( nr, asize = 2, balp = TRUE, use_rgb = TRUE, thres1 = 100, thres2 = 200, grad = TRUE )
nr |
A |
asize |
An integer scalar giving the aperture size parameter; the
actual Sobel kernel size used internally by Canny is |
balp |
A logical scalar. If |
use_rgb |
A logical scalar. If |
thres1 |
A numeric scalar giving the lower hysteresis threshold. |
thres2 |
A numeric scalar giving the upper hysteresis threshold. |
grad |
A logical scalar indicating whether to use a more accurate
gradient calculation ( |
use_rgb = FALSE)The input is converted to grayscale and passed to the Canny operator.
The aperture size of the Sobel derivative is 2 * asize - 1. When
balp = TRUE, the alpha channel is thresholded from the detected edges.
use_rgb = TRUE)Canny is applied independently to each RGB channel, and the resulting edge
maps are summed to form a combined edge representation. The alpha channel is
either thresholded (balp = TRUE) or preserved from the input.
border corresponds to:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_REFLECT_101
cv::BORDER_ISOLATED
A nativeRaster object.
Applies one of the predefined color filters that are ported from Rustagram.
color_filter( nr, filter = c("1977", "aden", "brannan", "brooklyn", "clarendon", "earlybird", "gingham", "hudson", "inkwell", "kelvin", "lark", "lofi", "maven", "mayfair", "moon", "nashville", "reyes", "rise", "slumber", "stinson", "toaster", "valencia", "walden") )color_filter( nr, filter = c("1977", "aden", "brannan", "brooklyn", "clarendon", "earlybird", "gingham", "hudson", "inkwell", "kelvin", "lark", "lofi", "maven", "mayfair", "moon", "nashville", "reyes", "rise", "slumber", "stinson", "toaster", "valencia", "walden") )
nr |
A |
filter |
The name of the filter. |
The following filters are available:
1977
aden
brannan
brooklyn
clarendon
earlybird
gingham
hudson
inkwell
kelvin
lark
lofi
maven
mayfair
moon
nashville
reyes
rise
slumber
stinson
toaster
valencia
walden
A nativeRaster object.
Maps grayscale or hue values of a nativeRaster image to a predefined color
lookup table (OpenCV colormaps). The input can be derived either from the
grayscale intensity or from the hue channel in HSV space. The mapped values
replace the image's color channels while preserving the alpha channel.
color_map(nr, map = 0, use_hsv = FALSE, inverse = FALSE)color_map(nr, map = 0, use_hsv = FALSE, inverse = FALSE)
nr |
A |
map |
An integer scalar specifying the colormap ID.
Must be one of |
use_hsv |
A logical scalar.
If |
inverse |
A logical scalar. If |
map corresponds to:
cv::COLORMAP_AUTUMN
cv::COLORMAP_BONE
cv::COLORMAP_JET
cv::COLORMAP_WINTER
cv::COLORMAP_RAINBOW
cv::COLORMAP_OCEAN
cv::COLORMAP_SUMMER
cv::COLORMAP_SPRING
cv::COLORMAP_COOL
cv::COLORMAP_HSV
cv::COLORMAP_PINK
cv::COLORMAP_HOT
cv::COLORMAP_PARULA
cv::COLORMAP_MAGMA
cv::COLORMAP_INFERNO
cv::COLORMAP_PLASMA
cv::COLORMAP_VIRIDIS
cv::COLORMAP_CIVIDIS
cv::COLORMAP_TWILIGHT
cv::COLORMAP_TWILIGHT_SHIFTED
cv::COLORMAP_TURBO
cv::COLORMAP_DEEPGREEN
A nativeRaster object.
Color manipulation
apply_lut1d(nr, lut) apply_lut3d(nr, cubefile) brighten(nr, intensity) contrast(nr, intensity) duotone(nr, color_a = "yellow", color_b = "navy", gamma = 2.2) grayscale(nr) hue_rotate(nr, rad) invert(nr) linocut(nr, ink = "navy", paper = "snow", threshold = 0.4) posterize(nr, shades = 4) reset_alpha(nr, alpha = 1) saturate(nr, intensity) sepia(nr, intensity, depth = 20) set_matte(nr, color = "green") solarize(nr, threshold = 0.5) unpremul(nr, max = 255L)apply_lut1d(nr, lut) apply_lut3d(nr, cubefile) brighten(nr, intensity) contrast(nr, intensity) duotone(nr, color_a = "yellow", color_b = "navy", gamma = 2.2) grayscale(nr) hue_rotate(nr, rad) invert(nr) linocut(nr, ink = "navy", paper = "snow", threshold = 0.4) posterize(nr, shades = 4) reset_alpha(nr, alpha = 1) saturate(nr, intensity) sepia(nr, intensity, depth = 20) set_matte(nr, color = "green") solarize(nr, threshold = 0.5) unpremul(nr, max = 255L)
nr |
A |
lut |
A 256x3 double matrix in range |
cubefile |
A character string specifying the path to the |
intensity |
A numeric scalar. |
gamma |
A numeric scalar. The gamma exponent. |
rad |
A numeric scalar. The rotation angle in radians. |
alpha, threshold
|
A numeric scalar in range |
depth, shades
|
A positive integer scalar. |
color, color_a, color_b, ink, paper
|
A character string; color name or hex code. |
max |
An integer scalar. The maximum value of the color code. |
A nativeRaster object.
Applies a custom convolution kernel to a nativeRaster image.
This function wraps OpenCV's filter2D,
allowing arbitrary linear filters
such as sharpening, blurring, or edge detection.
Optionally, the same convolution can be applied to the alpha channel.
convolve( nr, kernel = matrix(c(0, -1, 0, -1, 5, -1, 0, -1, 0), 3, 3), border = c(3, 4, 0, 1, 2), alphasync = FALSE )convolve( nr, kernel = matrix(c(0, -1, 0, -1, 5, -1, 0, -1, 0), 3, 3), border = c(3, 4, 0, 1, 2), alphasync = FALSE )
nr |
A |
kernel |
A numeric matrix giving the convolution kernel. Larger or weighted matrices can be used to define custom filters. The matrix is passed directly to OpenCV, which normalizes nothing automatically. |
border |
An integer scalar specifying the border-handling mode.
One of |
alphasync |
A logical scalar.
If |
border corresponds to the OpenCV extrapolation types:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_REFLECT_101
cv::BORDER_ISOLATED
A nativeRaster object.
Applies OpenCV's detailEnhance to a nativeRaster image.
This filter enhances fine structures such as
edges and textures while preserving the overall appearance of the image.
detail_enhance(nr, sgmS = 10, sgmR = 0.15)detail_enhance(nr, sgmS = 10, sgmR = 0.15)
nr |
A |
sgmS |
A numeric scalar giving the spatial sigma used for edge-preserving
filtering. Larger values increase the spatial smoothing radius.
Valid range: |
sgmR |
A numeric scalar giving the range sigma controlling how strongly
edges are preserved based on color differences.
Valid range: |
A nativeRaster object.
Applies an iterative diffusion-style filter to a nativeRaster image.
This custom process repeatedly blurs a gamma-transformed version of the
image and accumulates the diffused values with a decaying gain factor.
The result is then inverse–gamma–corrected, producing a soft, glowy,
detail-enhancing effect reminiscent of multi-scale diffusion or
photographic bloom.
diffusion_filter( nr, factor = 5, offset = 0.1, iter = 2, gamma = 1.3, sigma = 2 )diffusion_filter( nr, factor = 5, offset = 0.1, iter = 2, gamma = 1.3, sigma = 2 )
nr |
A |
factor |
A numeric scalar controlling the decay factor used at each iteration. Larger values reduce the contribution of later diffusion steps. |
offset |
A numeric scalar added to the iteration index when computing the decaying gain. Helps adjust the early-iteration weighting. |
iter |
An integer scalar giving the number of diffusion iterations to perform. More iterations strengthen the smoothing and glow effects. |
gamma |
A numeric scalar specifying the gamma exponent applied before
diffusion (and inverted afterward). Values greater than |
sigma |
An integer scalar giving the initial Gaussian blur radius (converted to a standard deviation internally). The value is squared on each iteration, producing progressively wider diffusion. |
A nativeRaster object.
Create a native raster filled with a color
fill_with(color, width, height)fill_with(color, width, height)
color |
Color name or hex code. |
width, height
|
A positive integer scalar. |
A nativeRaster object.
Performs histogram equalization on a nativeRaster image.
This function supports both standard histogram equalization
and adaptive histogram equalization (CLAHE).
Optionally, the equalized luminance can be merged back
into the original color channels to produce a color-preserving enhancement.
hist_eq(nr, limit = 40, grid = c(8, 8), adp = FALSE, color = TRUE)hist_eq(nr, limit = 40, grid = c(8, 8), adp = FALSE, color = TRUE)
nr |
A |
limit |
A numeric scalar giving the clip limit used for adaptive
histogram equalization (CLAHE). Ignored when |
grid |
An integer vector of length 2 specifying the grid size
( |
adp |
A logical scalar.
If |
color |
A logical scalar.
If |
A nativeRaster object.
These functions provide convenient helpers for reading still images, writing still images, and creating animated image files.
Since the underlying image writers always treat the input as 4 channels images, writing with some formats would fail even if the linked 'OpenCV' library supports it.
read_still(filename) read_data(x) write_still(nr, filename = "azny-still.png") write_data(nr, ext = ".jpeg", quality = 80) write_animation( frames, filename = "azny-anime.webp", delay = 1/12, quality = 80, loop_count = 0 )read_still(filename) read_data(x) write_still(nr, filename = "azny-still.png") write_data(nr, ext = ".jpeg", quality = 80) write_animation( frames, filename = "azny-anime.webp", delay = 1/12, quality = 80, loop_count = 0 )
filename |
A file name.
For |
x |
A raw vector containing image data. |
nr |
A |
ext |
File extension (e.g., ".jpg", ".png") to specify the output format. |
quality |
Image quality.
For |
frames |
A character vector of file names representing animation frames. |
delay |
Frame delay in seconds. Internally converted to milliseconds, with a minimum of 10ms. |
loop_count |
Number of animation loops.
A value of |
read_still():
Reads a still image file and converts it into a nativeRaster.
read_data():
Reads image data from a raw vector and converts it into a nativeRaster.
write_still():
Writes a still image file from a nativeRaster.
write_data():
Writes and returns the image data as a raw vector.
write_animation():
Writes an animated image file from a sequence of image files.
read_still() and read_data() return a nativeRaster object.
write_still() and write_animation() invisibly return filename.
write_data() returns a raw vector containing the image data.
This filter produces a painting-like, edge-aware smoothing effect inspired by the Kuwahara filter, but it does not implement the classical four-region Kuwahara algorithm.
Instead, it estimates local variance using kernel1 and
applies a softmax-like weighting (exp(-beta * variance)) to emphasize
smoother directions, then computes a weighted average using kernel2.
The method originates from the idea described in
https://qiita.com/Cartelet/items/7773cd56c7ce016476d9.
kuwahara_filter( nr, kernel1 = kernel_cone(7), kernel2 = kernel_cone(5), beta = 30, border = c(3, 4, 0, 1, 2) )kuwahara_filter( nr, kernel1 = kernel_cone(7), kernel2 = kernel_cone(5), beta = 30, border = c(3, 4, 0, 1, 2) )
nr |
A |
kernel1 |
A numeric matrix used to compute local mean and variance. |
kernel2 |
A numeric matrix used to compute the final weighted average. |
beta |
A double scalar controlling the sharpness of softmax weighting. Higher values make the filter more strongly directional. |
border |
An integer scalar. The type of pixel extrapolation method. |
border corresponds to the OpenCV extrapolation types:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_REFLECT_101
cv::BORDER_ISOLATED
A nativeRaster object.
Applies a Laplacian filter to detect edges in a nativeRaster image.
The Laplacian operator computes second-order derivatives, highlighting regions of rapid intensity change.
The result is returned as a 3-channel grayscale image, with optional binary alpha masking.
laplacian_filter( nr, ksize = 3, balp = TRUE, use_rgb = TRUE, border = c(3, 4, 0, 1, 2), scale = 1, delta = 0 )laplacian_filter( nr, ksize = 3, balp = TRUE, use_rgb = TRUE, border = c(3, 4, 0, 1, 2), scale = 1, delta = 0 )
nr |
A |
ksize |
An integer scalar specifying the kernel radius. The effective
Laplacian kernel size becomes |
balp |
A logical scalar. If |
use_rgb |
A logical scalar. If |
border |
An integer scalar selecting the border-handling mode. One of
|
scale |
A numeric scalar that scales the computed Laplacian derivative. |
delta |
A numeric scalar added to the filtered result before scaling. |
use_rgb = FALSE)The input image is converted to grayscale, normalized to [0, 1], and the
Laplacian operator is applied using a kernel of size 2 * ksize - 1. The
output is rescaled to [0, 255]. When balp = TRUE, the alpha channel is
thresholded based on edge intensity.
use_rgb = TRUE)The Laplacian operator is applied independently to each RGB channel, and the
channelwise derivatives are summed to produce a combined edge map. The alpha
channel is determined either by thresholding (balp = TRUE) or by preserving
the original.
border corresponds to:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_REFLECT_101
cv::BORDER_ISOLATED
A nativeRaster object.
Weaves short line segments across an image by scanning pixels and triggering strokes based on accumulated luminance.
This effect walks through the image in the selected direction.
At each pixel, luminance is accumulated and compared with phase.
When the threshold is reached,
a stroke event may start depending on init and interval,
and step pixels are drawn from fg; otherwise pixels are taken from bg.
lineweave( nr, fg = nr, bg = blurhash(nr, 3, 3), omega = 10, phase = 5, init = 1, interval = 1, step = 2, invert = FALSE, direction = c(3, 0, 1, 2) )lineweave( nr, fg = nr, bg = blurhash(nr, 3, 3), omega = 10, phase = 5, init = 1, interval = 1, step = 2, invert = FALSE, direction = c(3, 0, 1, 2) )
nr |
A |
fg |
A |
bg |
A |
omega |
A positive numeric scalar scaling how fast luminance accumulates per pixel. |
phase |
A positive numeric scalar giving the luminance threshold for triggering events. |
init |
A positive integer scalar giving the number of stroke events to emit in one cycle. |
interval |
A non-negative integer scalar giving the number of trigger events to skip between cycles. |
step |
A non-negative integer scalar giving the stroke length in pixels for each event. |
invert |
A logical scalar indicating whether bright pixels (instead of dark pixels) contribute more strongly to triggering. |
direction |
An integer giving the scan direction
|
A nativeRaster object.
A collection of helper functions that generate numeric matrices usable as
convolution kernels. These kernels are intended for use with convolve()
and other filtering operations in this package.
kernel_bayer(n, normalize = TRUE) kernel_cone(size) kernel_disc(size) kernel_emboss(theta, strength = 1) kernel_motion(size, theta) kernel_ring(size, thickness = 1) kernel_stripe(n, mod, step = 1)kernel_bayer(n, normalize = TRUE) kernel_cone(size) kernel_disc(size) kernel_emboss(theta, strength = 1) kernel_motion(size, theta) kernel_ring(size, thickness = 1) kernel_stripe(n, mod, step = 1)
n |
An integer specifying the number of rows and columns. |
normalize |
A logical scalar specifying whether the kernel should be
divided by its sum. Set to |
size |
An odd integer specifying the kernel size. |
theta |
A numeric value (in radians) specifying the orientation. |
strength |
A numeric value controlling emboss intensity.
Defaults to |
thickness |
A numeric value controlling ring thickness.
Defaults to |
mod |
An integer specifying the pattern modulus. |
step |
An integer specifying the pattern step size. |
The following kernel constructors are available:
kernel_bayer: A Bayer pattern kernel.
kernel_cone: A cone-shaped, radially weighted kernel.
kernel_disc: A uniformly weighted disc kernel.
kernel_emboss: A direction-aware emboss kernel.
kernel_motion: A linear motion kernel oriented by theta.
kernel_ring: A ring-shaped (donut-like) kernel.
kernel_stripe: A stripe pattern kernel.
A numeric matrix.
Applies mean shift filtering to a nativeRaster image.
This edge-preserving smoothing technique groups pixels
in joint spatial–color space,
producing a stylized effect with flattened regions
while retaining clear boundaries.
mean_shift(nr, sp = 10, sr = 30, max_level = 1)mean_shift(nr, sp = 10, sr = 30, max_level = 1)
nr |
A |
sp |
A numeric scalar giving the spatial window radius. Larger values increase the smoothing effect across neighboring pixels. |
sr |
A numeric scalar giving the color (range) window radius. Larger values allow grouping across larger color differences. |
max_level |
An integer scalar specifying the number of pyramid levels to process. Must be non-negative. |
A nativeRaster object.
Applies median cut color quantization to a nativeRaster image and returns
a new nativeRaster with a reduced palette.
This function groups similar colors into at most n_colors representative
colors. The representative color of each group is computed from the weighted
average of the original colors in that group.
If the number of unique colors in nr is already less than or equal to
n_colors, the input is returned unchanged.
median_cut(nr, n_colors = 16)median_cut(nr, n_colors = 16)
nr |
A |
n_colors |
Maximum number of colors in the output image. Must be a positive integer. |
A nativeRaster object.
Applies morphological image-processing operations to a nativeRaster image.
Depending on use_rgb, operations are applied either to the grayscale image
masked by the alpha channel or independently to each RGB channel with
per-channel structuring elements. Supported operations include erosion,
dilation, opening, closing, gradient, and related transforms.
morphology( nr, ksize = c(2, 2, 2), ktype = c(0, 1, 2), mode = c(0, 1, 2, 3, 4, 5, 6, 7), border = c(3, 4, 0, 1, 2), iterations = 1, alphasync = FALSE, use_rgb = TRUE, anchor = c(-1, -1) )morphology( nr, ksize = c(2, 2, 2), ktype = c(0, 1, 2), mode = c(0, 1, 2, 3, 4, 5, 6, 7), border = c(3, 4, 0, 1, 2), iterations = 1, alphasync = FALSE, use_rgb = TRUE, anchor = c(-1, -1) )
nr |
A |
ksize |
An integer vector specifying kernel size(s).
Must be non-negative. |
ktype |
An integer scalar selecting the structuring element shape.
One of |
mode |
An integer scalar selecting the morphological operation.
One of |
border |
An integer scalar selecting the border-handling mode.
One of |
iterations |
An integer scalar giving the number of repetitions of the operation. Must be grater than 0. |
alphasync |
A logical scalar. If |
use_rgb |
A logical scalar. If |
anchor |
An integer vector of length 2 specifying the anchor point
(kernel origin). Use |
The shape of the structuring element is controlled by ktype, and its size
is determined by ksize.
When use_rgb = FALSE, ksize must be a single non-negative integer.
When use_rgb = TRUE, ksize must be a length-3 integer vector, allowing
separate kernel sizes for the R, G, and B channels.
The location of the anchor (kernel origin) can be specified via anchor.
Use c(-1, -1) for the default centered anchor.
If alphasync = TRUE, the same morphological operation is applied to the
alpha channel. Otherwise, the alpha channel is preserved.
ktype corresponds to:
cv::MORPH_RECT
cv::MORPH_CROSS
cv::MORPH_ELLIPSE
mode is an integer scalar in range [0, 7] corresponding to:
cv::MORPH_ERODE
cv::MORPH_DILATE
cv::MORPH_OPEN
cv::MORPH_CLOSE
cv::MORPH_GRADIENT
cv::MORPH_TOPHAT
cv::MORPH_BLACKHAT
cv::MORPH_HITMISS
border corresponds to:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_REFLECT_101
cv::BORDER_ISOLATED
A nativeRaster object.
Applies an oil-paint–style effect to a nativeRaster image.
This filter produces a painterly appearance
by quantizing and aggregating colors within a local neighborhood.
oilpaint(nr, size = 10, ratio = 1)oilpaint(nr, size = 10, ratio = 1)
nr |
A |
size |
An integer scalar specifying the radius of the neighborhood
used for computing the oil painting effect. Must be at least |
ratio |
An integer scalar controlling the number of intensity bins used in the stylization process. Larger values preserve finer variations in tone. |
A nativeRaster object.
Pack and unpack RGBA values
pack_color(r, g, b, a) unpack_color(x)pack_color(r, g, b, a) unpack_color(x)
r, g, b, a
|
Numeric vectors of equal length in range |
x |
An integer vector that contains native packed integers. |
Integers.
Generates a pencil-sketch–style rendering of a nativeRaster image.
This filter produces grayscale or color pencil–like strokes by combining
edge extraction with tone mapping.
pencil_sketch(nr, sgmS = 60, sgmR = 0.07, shade = 0.02, color = TRUE)pencil_sketch(nr, sgmS = 60, sgmR = 0.07, shade = 0.02, color = TRUE)
nr |
A |
sgmS |
A numeric scalar giving the spatial sigma controlling the
smoothness of the underlying edge-preserving filter.
Valid range: |
sgmR |
A numeric scalar giving the range sigma controlling sensitivity
to color differences when building the sketch effect.
Valid range: |
shade |
A numeric scalar specifying the shading factor determining
how much texture is included in the sketch.
Valid range: |
color |
A logical scalar.
If |
A nativeRaster object.
This function scans a nativeRaster image and returns the positions
(row, column, and linear index) of pixels whose values fall within a given
range.
Optionally, pixels can be grouped into contiguous runs along rows or columns, and only runs of a minimum length can be retained. This makes it suitable as a building block for pixel sorting or other effects that operate on contiguous pixel segments.
pixel_positions( nr, range = c(0, 0.5), by = c("luma", "blue", "green", "red", "hue", "luminance", "saturation"), direction = c("row", "col"), min_length = 1 )pixel_positions( nr, range = c(0, 0.5), by = c("luma", "blue", "green", "red", "hue", "luminance", "saturation"), direction = c("row", "col"), min_length = 1 )
nr |
A |
range |
A numeric vector of length 2 specifying the lower and upper
bounds (in |
by |
A string specifying which pixel value to use for selection. |
direction |
Direction used to define contiguous runs when
|
min_length |
Minimum length of contiguous pixel runs to retain.
If |
Pixel values are normalized to the range [0, 1] before comparison.
For "hue", "luminance", and "saturation", the image is
internally converted to HLS color space using OpenCV.
If min_length <= 1, a tibble with columns:
row: Row index (1-based).
col: Column index (1-based).
index: Linear index in the nativeRaster vector (1-based).
If min_length > 1, a tibble with columns:
group: Row or column index defining the scan direction.
pos: Position within each group.
run: Contiguous run identifier.
index: Linear index in the nativeRaster vector (1-based).
Applies an edge-preserving smoothing filter to a nativeRaster image.
This filter attenuates noise and texture while retaining sharp boundaries,
producing a clean, stylized appearance.
preserve_edge(nr, sgmS = 60, sgmR = 0.44, recursive = TRUE)preserve_edge(nr, sgmS = 60, sgmR = 0.44, recursive = TRUE)
nr |
A |
sgmS |
A numeric scalar giving the spatial sigma, which controls the
effective smoothing radius.
Valid range: |
sgmR |
A numeric scalar giving the range sigma, which determines how
strongly edges are preserved based on color differences.
Valid range: |
recursive |
A logical scalar.
If |
A nativeRaster object.
These functions provide flexible image scaling based on OpenCV's
resize, supporting both direct resizing and two-stage
downsample–upsample resampling. The operations apply to all BGRA channels.
resize( nr, wh = c(1, 1), resize_mode = c(1, 2, 3, 4, 5, 6, 0), set_size = FALSE ) resample( nr, wh = c(0.2, 0.2), resize_mode1 = c(1, 2, 3, 4, 5, 6, 0), resize_mode2 = c(1, 2, 3, 4, 5, 6, 0) )resize( nr, wh = c(1, 1), resize_mode = c(1, 2, 3, 4, 5, 6, 0), set_size = FALSE ) resample( nr, wh = c(0.2, 0.2), resize_mode1 = c(1, 2, 3, 4, 5, 6, 0), resize_mode2 = c(1, 2, 3, 4, 5, 6, 0) )
nr |
A |
wh |
A numeric vector of length 2.
|
resize_mode |
An integer scalar selecting the interpolation mode for |
set_size |
A logical scalar.
If |
resize_mode1 |
An integer scalar giving the interpolation mode for the
downsampling step in |
resize_mode2 |
An integer scalar giving the interpolation mode for the
upsampling step in |
resize()Resizes an image either by specifying a scaling factor (wh) or, when
set_size = TRUE, by specifying a target width and height directly.
Interpolation is controlled through resize_mode.
resample()Downsamples and then upsamples an image, potentially using different interpolation modes for reduction and expansion. This can be used to create stylized pixelation or texture effects, depending on the scaling factors and interpolation methods.
A nativeRaster object.
Applies a tiled tone/texture to an image using a grayscale
threshold map (pattern). For each pixel, the input intensity is compared
with the corresponding value in pattern (plus cutoff), and then either
lift or bias is added to the pixel value.
This is useful for creating retro print-like textures, ordered-tone patterns,
or "screen tone" overlays when pattern is a tiled image.
screen_tone(nr, pattern, bias = 0L, lift = 60L, cutoff = 8L)screen_tone(nr, pattern, bias = 0L, lift = 60L, cutoff = 8L)
nr |
A |
pattern |
A |
bias |
Integer. Value to add to pixels that do not pass the threshold.
Larger values brighten the corresponding regions (clamped to |
lift |
Integer. Value to add to pixels that pass the threshold.
Larger values brighten the corresponding regions (clamped to |
cutoff |
Integer. Offset added to |
A nativeRaster object.
Applies a Sobel filter to extract edges from a nativeRaster image. The
operation can be performed on a grayscale conversion or by aggregating
per-channel gradients from the RGB channels. The resulting edge intensity is
returned as a 3-channel grayscale image, with optional binary alpha masking.
sobel_filter( nr, ksize = 3, balp = TRUE, use_rgb = TRUE, border = c(3, 4, 0, 1, 2), dx = 1, dy = dx, scale = 1, delta = 0 )sobel_filter( nr, ksize = 3, balp = TRUE, use_rgb = TRUE, border = c(3, 4, 0, 1, 2), dx = 1, dy = dx, scale = 1, delta = 0 )
nr |
A |
ksize |
An integer scalar giving the filter radius. The actual Sobel
kernel size becomes |
balp |
A logical scalar. If |
use_rgb |
A logical scalar. If |
border |
An integer scalar selecting the border-handling mode. One of
|
dx |
An integer scalar specifying the order of the derivative in x. |
dy |
An integer scalar specifying the order of the derivative in y. |
scale |
A numeric scalar scaling the computed Sobel derivative. |
delta |
A numeric scalar added to the results prior to scaling. |
use_rgb = FALSE)The image is converted to grayscale, normalized to [0, 1], and the Sobel
derivative is computed using the specified derivative orders dx, dy, and
kernel size ksize. Edges are mapped to [0, 255]. When balp = TRUE,
the alpha channel is binarized based on the detected edges.
use_rgb = TRUE)Sobel derivatives are computed independently for each RGB channel and summed
to produce a combined edge response. The alpha channel is either binarized
from the edge map (balp = TRUE) or preserved from the input.
border corresponds to:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_REFLECT_101
cv::BORDER_ISOLATED
A nativeRaster object.
Applies a stylization effect to a nativeRaster image.
This filter combines edge-aware smoothing
and abstraction to produce a painterly,
cartoon-like appearance while preserving prominent structures.
stylize(nr, sgmS = 60, sgmR = 0.44)stylize(nr, sgmS = 60, sgmR = 0.44)
nr |
A |
sgmS |
A numeric scalar giving the spatial sigma controlling the
smoothness of the stylization process.
Valid range: |
sgmR |
A numeric scalar giving the range sigma determining sensitivity
to color differences during abstraction.
Valid range: |
A nativeRaster object.
Remaps color or alpha channels of a nativeRaster image using arbitrary
pairwise assignments. This function wraps OpenCV's mixChannels, allowing
reordering or selective copying of the BGRA channels.
swap_channels(nr, from = c(0, 1, 2, 3), to = c(1, 2, 0, 3))swap_channels(nr, from = c(0, 1, 2, 3), to = c(1, 2, 0, 3))
nr |
A |
from |
An integer vector of length 4 giving the source channel indices
( |
to |
An integer vector of length 4 giving the destination channel
indices ( |
A nativeRaster object.
Performs global (fixed) thresholding or adaptive thresholding on a
nativeRaster image.
Both functions operate on a grayscale conversion of the input
and return a 3-channel binary (0/maxv) image with the original alpha
preserved.
thres(nr, threshold = 100, maxv = 255, mode = c(0, 1, 2, 3, 4, 5, 6)) adpthres(nr, maxv = 255, bsize = 1, C = 5, mode = c(0, 1), invert = FALSE)thres(nr, threshold = 100, maxv = 255, mode = c(0, 1, 2, 3, 4, 5, 6)) adpthres(nr, maxv = 255, bsize = 1, C = 5, mode = c(0, 1), invert = FALSE)
nr |
A |
threshold |
A numeric scalar in |
maxv |
A numeric scalar in
|
mode |
An integer scalar specifying the thresholding mode.
|
bsize |
An integer scalar in |
C |
A numeric scalar subtracted from the local threshold (used by OpenCV). Controls how strong the threshold offset is. |
invert |
A logical scalar.
If |
thres()Applies a fixed threshold to the grayscale image.
Pixels with values greater than threshold
(depending on the thresholding mode) are set to maxv;
others are set to 0.
The behavior is controlled by the thresholding mode, which corresponds to
OpenCV's threshold types.
adpthres()Applies adaptive thresholding, where the threshold value is computed locally
for each pixel based on a neighborhood mean or Gaussian-weighted sum. The
block size and constant C adjust how the local threshold is computed.
For thres, mode is an integer scalar in range [0, 6] corresponding to:
cv::THRESH_BINARY
cv::THRESH_BINARY_INV
cv::THRESH_TRUNC
cv::THRESH_TOZERO
cv::THRESH_TOZERO_INV
cv::THRESH_OTSU
cv::THRESH_TRIANGLE
A nativeRaster object.
Repeats a numeric matrix x to fill an image of size
width by height, then returns it as a grayscale nativeRaster
(RGB channels are identical; alpha is set to 255).
This is mainly intended to build threshold/texture maps for effects such as
screen_tone(), where small matrices (e.g. Bayer matrices or custom kernels)
are tiled across an image.
Values are clamped to [0, 255] before being packed.
tile_matrix(x, width, height)tile_matrix(x, width, height)
x |
A numeric matrix. Interpreted as a single-channel pattern. |
width, height
|
Integers. Output image width and height in pixels. |
A nativeRaster of dimensions height * width.
# 4x4 Bayer matrix, scaled to 0..255 b4 <- kernel_bayer(4, normalize = FALSE) * 255 ## Not run: pat <- tile_matrix(b4, width = 320, height = 180) grid::grid.newpage() grid::grid.raster(pat, interpolate = FALSE) ## End(Not run)# 4x4 Bayer matrix, scaled to 0..255 b4 <- kernel_bayer(4, normalize = FALSE) * 255 ## Not run: pat <- tile_matrix(b4, width = 320, height = 180) grid::grid.newpage() grid::grid.raster(pat, interpolate = FALSE) ## End(Not run)
Warps an image using a perspective transformation, keeping the same dimensions as the input image.
warp_perspective(nr, mat = diag(1, 3), border = c(3, 4, 0, 1, 2))warp_perspective(nr, mat = diag(1, 3), border = c(3, 4, 0, 1, 2))
nr |
A |
mat |
A 3x3 matrix specifying the perspective transformation. |
border |
An integer scalar selecting pixel extrapolation method. |
border corresponds to the OpenCV extrapolation types:
cv::BORDER_CONSTANT
cv::BORDER_REPLICATE
cv::BORDER_REFLECT
cv::BORDER_WRAP
cv::BORDER_REFLECT_101
A nativeRaster object.