rm_background: Remove image background

Description Usage Arguments Examples

View source: R/ipa.R

Description

Remove image background

Usage

1
2
3
4
5
6
7
8
rm_background(
  image_path,
  bkg_thr = 0.4,
  plot = FALSE,
  trim_areas = NULL,
  quiet = TRUE,
  ...
)

Arguments

image_path

filename w/o the full path

bkg_thr

background threshold, any pixel below this value will be set to zero (black) and one (white) in the alpha layer, to create a transparency effect.

plot

boolean flag on whether or not to generate a histogram of the pixel values. This can be used to determine an optimal bkg_thr

trim_areas

data frame containing areas to be trimmed (add transparency). Each row must have the same format of area as in add_alpha: 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

...

extra parameters for hist

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
    test_data <- data.frame(name = c("R", "G"), values = c(2, 2))
    RG <- c("red", "green")
    png("test_plot.png")
    par(bg = 'black')
    barplot(height = test_data$values, names = test_data$name, col = RG)
    dev.off()
    rm_background("test_plot.png", 0.1)
    rm_background("test_plot.png", 0.1, TRUE)
    rm_background("test_plot.png", 0.1, TRUE, breaks = 10)
    trim_areas <- data.frame(x0 = 1, width = -1, y0 = 1, height = 100)
    trim_areas <- rbind(trim_areas, c(1, -1, -1, 100))
    rm_background("test_plot.png", 0.1, TRUE, trim_areas, breaks = 10)

## End(Not run)

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