add_alpha: Add transparency (set pixels to zero) area to image

Description Usage Arguments Value Examples

View source: R/ipa.R

Description

Add transparency (set pixels to zero) area to image

Usage

1
add_alpha(img, area, quiet = TRUE)

Arguments

img

image object (cimg class)

area

area to modify: c(x0, width, y0, height) where: x0 is the starting pixel on the x-axis, width is the number of pixels along x, y0 is the starting pixel on the y-axis, and height is the number of pixels along y

To invert the area (trim right to left or bottom to top), set x0 = -1 or y0 = -1 respectively.

To modify from x0 to full width, set width = -1. Similarly, for the full height, set height = -1.

quiet

boolean flag to hide messages of work area

Value

modified image object (cimg class)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## Not run: 
    # Create test image
    red <- matrix(0, 50, 50)
    red[1:25, 1:25] <- 1
    blue <- matrix(0, 50, 50)
    blue[26:50, 1:25] <- 1
    green <- matrix(0, 50, 50)
    green[1:25, 26:50] <- 1
    alpha <- matrix(1, 50, 50)
    alpha[26:50, 26:50] <- 0
    img <- imager::as.cimg(abind::abind(imager::as.cimg(red),
                                        imager::as.cimg(blue),
                                        imager::as.cimg(green),
                                        imager::as.cimg(alpha),
                                        along = 4))
    # Remove red portion of the image
    plot(add_alpha(img, c(1, 25, 1, 25)))
    # Remove red and green portions
    plot(add_alpha(img, c(1, -1, 1, 25)))
    # Remove red and blue portions
    plot(add_alpha(img, c(1, 25, 1, -1)))
    # Remove green and alpha portions
    plot(add_alpha(img, c(-1, 25, 1, -1)))

## End(Not run)

villegar/IPA documentation built on Aug. 11, 2021, 12:50 a.m.