RNotes | EBImage


library(EBImage)

Image Display

Display a single image

x <- readImage(system.file("images", "sample-color.png", package="EBImage"))[257:768,,]
display(x, "Sample")

Display a thresholded sequence …

y <- readImage(system.file("images", "sample.png", package="EBImage"))
yt <- list()
for (t in seq(0.1, 5, len=9)) yt=c(yt, list(gblur(y, s=t)))
yt <- combine(yt)

… using the browser viewer …

display(yt, "Blurred images")
## The image contains more than one frame: only the first one is displayed. To display all frames use 'all = TRUE'.

display(yt, "Blurred images", all=TRUE)

… or using R’s build-in raster functions

display(resize(yt, 256, 256), method = "raster", all = TRUE)

Display the last frame

display(yt, method = "raster", frame = numberOfFrames(yt, type = "render"))

Image I/O

Read and display an image

f <- system.file("images", "sample-color.png", package="EBImage")
x <- readImage(f)
display(x)

Read and display a multi-frame TIFF

y <- readImage(system.file("images", "nuclei.tif", package="EBImage"))
display(y)
## The image contains more than one frame: only the first one is displayed. To display all frames use 'all = TRUE'.

display(y, all=TRUE)

Read an image directly from a remote location by specifying its URL

try({
  im <- readImage("http://www-huber.embl.de/EBImage/ExampleImages/berlin.tif")
  display(im, title = "Berlin Impressions", all=TRUE)
})

Convert a PNG file into JPEG

tempfile <- tempfile("", , ".jpeg")
writeImage(x, tempfile, quality = 85)
cat("Converted '", f, "' into '", tempfile, "'.\n", sep="")
## Converted 'C:/Users/Earl/Documents/R/win-library/3.1/EBImage/images/sample-color.png' into 'C:\Users\Earl\AppData\Local\Temp\RtmpyKyohe\1b70554a6815.jpeg'.

Save a frame sequence

files <- writeImage(y, tempfile("", , ".jpeg"), quality = 85)
cat("Files created: ", files, sep="\n")
## Files created: 
## C:\Users\Earl\AppData\Local\Temp\RtmpyKyohe\1b706a020bd-0.jpeg
## C:\Users\Earl\AppData\Local\Temp\RtmpyKyohe\1b706a020bd-1.jpeg
## C:\Users\Earl\AppData\Local\Temp\RtmpyKyohe\1b706a020bd-2.jpeg
## C:\Users\Earl\AppData\Local\Temp\RtmpyKyohe\1b706a020bd-3.jpeg

packageVersion("EBImage")
## [1] '4.8.2'

efg
2015-01-18 1957