image_crop_baselineareas: Extract areas between baselines

View source: R/img.R

image_crop_baselineareasR Documentation

Extract areas between baselines

Description

Extract areas between baselines

Usage

image_crop_baselineareas(
  image,
  x,
  textregion,
  extend = TRUE,
  horiz = FALSE,
  enlarge = 0,
  color = "royalblue",
  border = "10x10",
  overview = TRUE,
  max_width = +Inf,
  trace = FALSE,
  ...
)

Arguments

image

image either an object of class opencv-image or a path to an image file on disk

x

a list vector where each list element contains columns x and y indicating the positions of the baseline

textregion

a list vector of the same length of x where each list element contains columns x and y indicating the positions of textregion. The extracted areas can not pass these boundaries

extend

logical indicating to extend the baseline to the left and right of the image. Defaults to TRUE.

horiz

logical indicating to extend the baselines horizontally. Defaults to FALSE.

enlarge

argument passed on to st::buffer to increase the size of the extracted polygon

color

color to use for adding a border in the overview image. Defaults to 'royalblue'.

border

border pixels to using in the overview image. Defaults to 10x10 pixel borders.

overview

logical indicating to add the overview image of all area's below each other. Defaults to TRUE.

max_width

maximum width of the overview image. Defaults to +Inf

trace

logical indicating to trace progress

...

further arguments currently not used

Value

a list with elements areas and overview where overview is a magick-image with stacked image lines and areas is a list of magick-image's, one for each text line
In case overview is set to FALSE the return value is only the list of stacked image lines.

Examples

library(opencv)
library(magick)
path     <- system.file(package = "madoc.utils", "extdata", "pagexml-example.xml")
x        <- read_pagexml(path)
x
img      <- system.file(package = "madoc.utils", "extdata", "pagexml-example.jpg")
img      <- ocv_read(img)
areas    <- image_crop_baselineareas(img, x = x$baseline, extend = FALSE, trace = TRUE)
areas$areas
image_resize(areas$overview, "x600")
areas    <- image_crop_baselineareas(img, x = x$baseline, extend = TRUE, color = "red")
image_resize(areas$overview, "x600")

## Multiple regions
path     <- system.file(package = "madoc.utils", "extdata", "multiregion-page.xml")
x        <- read_pagexml(path)
x
img      <- system.file(package = "madoc.utils", "extdata", "multiregion.jpg")
img      <- ocv_read(img)
areas    <- image_crop_baselineareas(img, 
                                     x = x$baseline, textregion = x$points, 
                                     extend = TRUE, overview = FALSE)
overview <- image_rbind(areas, color = "grey", geometry = "5x5")
image_resize(overview, "600")                                      

DIGI-VUB/madoc.utils documentation built on Sept. 14, 2022, 3:03 p.m.