EBImage: Annotate multiple images in a grid with display()?
1
0
Entering edit mode
maltethodberg ▴ 180
@maltethodberg-9690
Last seen 3 hours ago
Denmark

I'm using the EBImage package to plot a 6x6 grid of jpeg files using:

display(readImage(JPEGs), method="raster", all=TRUE, nx=6)

Is at possible to add a label to each individual image in the grid?

Something like. 1., 2., 3,. 4., / A, B, C, D. in the top left corner of each image.

EBImage display • 1.3k views
ADD COMMENT
3
Entering edit mode
Andrzej Oleś ▴ 750
@andrzej-oles-5540
Last seen 4.0 years ago
Heidelberg, Germany

Thanks for reaching out!

For labeling the image use the standard R graphics function text like in the following example.

library(EBImage)
library(magrittr)

## generate sample image sequence
images = readImage(system.file("images", "sample-color.png", package="EBImage"))
seq(from=0.5, to=5, length=6) %>%
  lapply(function(s) gblur(images, s, boundary="replicate")) %>%
  combine -> images

## parameters for placing the labels
nx = 2
ny = 3
width = dim(images)[1]
height = dim(images)[2]
x_offset = y_offset = 20
n = numberOfFrames(images, 'render')

## actual plotting
display(images, method = "raster", all = TRUE, nx = 2)
text(x = rep(seq(from = 0, by = width, length.out = nx), ny) + x_offset,
     y = rep(seq(from = 0, by = height, length.out = ny), each = nx) + y_offset,
     label = LETTERS[1:n], 
     adj = c(0,1), col = "white", cex = 1.5)

result

ADD COMMENT
0
Entering edit mode

Excellent! This works perfectly. Might be worth adding that little snippet of code to the examples in display(), or maybe the vignette? Now I have your attention, is there a similarly easy way to a common header for the entire plot?

ADD REPLY

Login before adding your answer.

Traffic: 668 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6