UP | HOME |

Plot array images: representar imágenes png

2026-04-22

Plot array images: representar imágenes png

Para representar matrices de datos que representan imágenes de tipo png, tal como se obtienen usando el paquete png o el pdftools, la siguiente función plot_array simplifica su visualización. Modificando rowlimits o collimits se consigue un zoom.

require(pdftools)
library(png)
plot_array <- function(image,rowlimits=c(1L,dim(image)[1]),collimits=c(1L,dim(image)[2]),...){
    par(mai=c(0,0,0,0),bty="n",bty = "n", xaxs = "i", yaxs = "i", xaxt = "n", yaxt = "n", col = "white") # margins
    plot(collimits, rowlimits, type = "n", xlab = "", ylab = "",...)
    rasterImage(image, 1, 1, dim(image)[2], dim(image)[1],...)
}

ficheropdf <- file.path(Sys.getenv("R_DOC_DIR"), "NEWS.pdf")
image <- pdf_render_page(ficheropdf,page=1,dpi=72,numeric=TRUE) # Convert into a matrix
plot_array(image)
str(image)


pdf_pagesize(ficheropdf) # size of page (dpi=72)
pdf_data(ficheropdf) # width height x y space text