EBImage: Annotate multiple images in a grid with display()?
1
0
Entering edit mode
maltethodberg ▴ 140
@maltethodberg-9690
Last seen 2 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 • 139 views
3
Entering edit mode
Andrzej Oleś ▴ 750
@andrzej-oles-5540
Last seen 8 months 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
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)


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?