Skip to main content
v2026.11,986 entries · CC-BY 4.0

Image Processing in R: magick, EBImage and imager

Install and run image processing in R with magick, EBImage and imager: commands, output, troubleshooting and a package comparison.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

Image processing in R is done with add-on packages, and three cover most research work: magick (a binding to ImageMagick for converting, resizing and filtering ordinary image files), EBImage (a Bioconductor package for analysing microscopy images and segmenting cells) and imager (a CImg-based package for fast filtering and morphology on images of up to four dimensions). This guide shows how to install each one, run a first task with commands taken from the package documentation, read the output, fix common installation problems and choose between them. It also covers the variants people search for as “r image processing” and “r package for image processing”.

What image processing in R is used for in research

Researchers use R for images when the picture is data: a microscope field to count nuclei in, a scanned plate to measure, a figure that has to be converted to a journal-ready format. Working in R keeps the whole chain, from file to table to statistical test, in one reproducible script. That is the same argument made in what R programming is used for: analysis steps become code that others can rerun.

The three packages answer different needs. magick describes itself through ImageMagick: it reads, converts, scales, blurs and writes files in many formats. EBImage is documented by Bioconductor as providing general purpose functionality for image processing and analysis, specifically including segmenting cells and extracting quantitative cellular descriptors from microscopy-based assays. imager is described on CRAN as fast image processing for images in up to 4 dimensions, built on the CImg library, with filtering and morphology functions.

R package for image processing: which one to start with

Start with magick when the job is file handling (format conversion, resizing, annotation, preparing figures). Start with EBImage when the job is quantitative bioimage analysis, because its documentation is organised around segmentation and cell measurements. Start with imager when you want numerical filtering on array data and need an extra dimension for depth or time. The data table below this guide compares the three on install route, version checked, license, system requirements and how each represents an image.

The table that follows lists the function each package uses for two common first steps. Each name comes from that package’s own documentation.

Package Read an image Smooth (blur) an image
magick image_read() image_blur()
EBImage readImage() gblur() (Gaussian smoothing)
imager load.image() isoblur()

How to install or access it

magick

magick is on CRAN. Install it with install.packages("magick"). The package documentation states that the CRAN binaries for Windows and macOS include most features, so no separate ImageMagick install is normally needed there. Building from source needs the ImageMagick C++ library: libmagick++-dev on Debian and Ubuntu, ImageMagick-c++-devel on Fedora, and brew install imagemagick@6 on macOS, where the documentation warns that librsvg and fontconfig are disabled. CRAN lists version 2.9.1, published 2026-02-28, under an MIT plus file license, with ImageMagick++ as its system requirement. After loading the package, magick_config() reports which formats and features your build supports. Optical character recognition (image_ocr) needs the separate tesseract package.

EBImage

EBImage is distributed through Bioconductor, not CRAN. Install it with BiocManager::install("EBImage") and load it with library("EBImage"). The Bioconductor release page lists version 4.54.0 (Bioconductor 3.23, R 4.6) under the LGPL license, and no system requirements are listed. Its authors are Oles, Pau, Smith, Sklyar and Huber. Its introductory vignette states that readImage takes a file name or URL and supports JPEG, PNG and TIFF files.

imager

imager is on CRAN: install.packages("imager"). CRAN lists version 1.0.8, published 2025-12-23, under LGPL-3, with fftw3, libtiff and X11 as system requirements. The package documentation says PNG, JPEG and BMP files are read natively, other formats go through ImageMagick, and video needs ffmpeg.

Step-by-step: a first task in each package

Step 1 with magick: read, resize, blur and write

  1. Load the package: library(magick).
  2. Read a file, a URL or raw bytes: img = image_read("figure.png"). For a vector image the documentation uses image_read_svg(url, width = 350).
  3. Scale to a width: image_scale(img, "300") sets the width to 300 pixels. Fit within a box with image_resize(img, "300x300").
  4. Blur: image_blur(img, 10, 5).
  5. Convert format: image_convert(img, "png").
  6. Write the result: image_write(img, path = "out.png", format = "png"). Setting path = NULL writes to memory instead, and the function returns the path otherwise.

Two behaviours matter for scripts. Every transformation returns a modified copy, so the original object is unchanged unless you assign the result back. Rendering is lazy, which is why a freshly printed image often shows a file size of 0.

Step 2 with EBImage: read, smooth, threshold and label objects

  1. Install and load as above, then read the sample nuclei image shipped with the package: nuc = readImage(system.file("images", "nuclei.tif", package = "EBImage")).
  2. Show all frames in a grid: display(nuc, method = "raster", all = TRUE). The vignette also describes method = "browser".
  3. Smooth with nuc_gblur = gblur(nuc, sigma = 5). The vignette says the wrapper adjusts the filter size automatically to the sigma.
  4. Threshold adaptively: nmask = thresh(nuc, w = 10, h = 10, offset = 0.05). The vignette describes this as adaptive thresholding with a linear filter using a rectangular box.
  5. Clean up and label: the vignette’s own nuclei example continues with opening(nmask, makeBrush(5, shape = "disc")), fillHull(nmask) and bwlabel(nmask).
  6. Resize with resize(img, w = 256, h = 256); if you give only one of width or height, the other is computed to keep the aspect ratio. Save with writeImage(img, "sample.jpeg", quality = 85); the vignette notes that JPEG quality runs from 1 to 100 and defaults to 100.

The vignette explains that bwlabel finds every connected set of pixels other than the background and relabels these sets with a unique increasing integer, and that it works on non-touching objects. For touching objects it points to watershed and propagate.

Step 3 with imager: load, convert and filter

  1. Load the package and the sample image: library(imager), then parrots = load.image(system.file("extdata/parrots.png", package = "imager")).
  2. Inspect it with dim(parrots), which the documentation shows as 768 512 1 3.
  3. Convert to grayscale with grayscale(parrots); the dimensions become 768 512 1 1.
  4. Blur with isoblur(im, 10).
  5. Threshold and split into connected regions with threshold and split_connected, then plot with plot(im).

Output and how to read it

What a magick object prints

Printing a magick image gives one row per frame with its format, width, height, colorspace, matte, file size and density. A GIF or multi-page PDF therefore prints several rows. image_info() returns similar information, comparable to the ImageMagick identify command.

What an EBImage object holds

An EBImage Image object stores pixel intensities in a numeric array in its .Data slot, plus a colormode slot. For the vignette’s grayscale example the array is 768 by 512 and range(img) returns 0 to 1, so intensities are scaled to that interval. Printing the object shows color mode, storage mode, dimensions and the number of frames. Because it behaves like an ordinary array, base R functions such as dim and hist work on it.

What an imager image holds

An imager cimg object is a four-dimensional array indexed x, y, z (depth or time) and c (colour, called spectrum). The width(), height(), depth() and spectrum() functions read each dimension. Coordinates start at (1,1) in the top-left corner and y increases downward, which is the opposite of a conventional plot axis and a common source of off-by-one and flipped-image mistakes.

Why this matters for analysis: with an array representation (EBImage, imager) you can subset and compute on pixel values directly. magick keeps the image inside ImageMagick and hands back transformed copies, which suits file preparation more than measurement. For presenting results, heatmaps in R and animations in R cover ways to display derived matrices and frame sequences.

Troubleshooting

magick will not install on Linux

The source build needs the ImageMagick C++ headers. Install libmagick++-dev on Debian or Ubuntu, or ImageMagick-c++-devel on Fedora, then reinstall the package. CRAN lists exactly this as the system requirement.

A format or feature is missing

Run magick_config() to see what your build supports. On macOS the Homebrew imagemagick@6 route is documented as having librsvg and fontconfig disabled, so SVG rendering and font features can be absent there. OCR needs the tesseract package in addition.

imager fails to build

CRAN lists fftw3, libtiff and X11 as system requirements. Install the matching development libraries for your operating system before reinstalling. For formats other than PNG, JPEG and BMP, imager relies on ImageMagick, and for video on ffmpeg.

EBImage will not install with install.packages

EBImage is not on CRAN, so install.packages("EBImage") is the wrong route. Use BiocManager::install("EBImage").

The image looks wrong after loading

Check the dimensions first (dim()) and, for imager, remember the four-dimensional layout and the top-left origin described above.

Free alternatives and the wider toolset

All three R packages are free and open source: magick under MIT plus file license, EBImage under LGPL and imager under LGPL-3, according to their official pages. The data table below this guide sets them side by side. If you would rather work in a point-and-click application than in code, Fiji and ImageJ are the standard free options for bioimage analysis, and R code can be used afterwards for the statistics. For preparing data frames of measurements extracted from images, see the dplyr package in R.

Frequently asked questions

What is the best R package for image processing?

There is no single best package; the choice follows the task. magick handles file conversion and resizing, EBImage targets microscopy and cell segmentation, and imager targets fast array filtering with up to four dimensions. Each package’s own documentation states these scopes.

How do I read an image in R?

Use image_read() in magick, readImage() in EBImage or load.image() in imager. magick’s image_read() accepts a path, a URL or raw bytes; EBImage’s readImage() accepts a file name or URL.

Which package should I use for microscopy images?

EBImage, which Bioconductor describes as providing functionality to segment cells and extract quantitative cellular descriptors from microscopy-based assays.

Do I need to install ImageMagick separately for magick?

Not normally on Windows or macOS, where the documentation says the CRAN binaries include most features. When building from source you need the ImageMagick C++ library for your platform.

Can R process images with more than two dimensions?

Yes. imager represents images as four-dimensional arrays (x, y, depth or time, colour), and EBImage objects can hold multiple frames.

Sources

Data: R image-processing packages compared: magick, EBImage and imager

Compares three R image-processing packages on install route, version checked, license, listed system requirements and how each represents an image, compiled from the official CRAN, Bioconductor and package documentation pages.

Period covered: 2025/2026.

R image-processing packages compared: magick, EBImage and imager
PackageInstall routeVersion checkedLicenseListed system requirementsImage representation
magickCRAN: install.packages("magick")2.9.1 (published 2026-02-28)MIT + file LICENSEImageMagick++ (libmagick++-dev on Debian/Ubuntu, ImageMagick-c++-devel on Fedora)Image object handled by ImageMagick; one row per frame when printed; transforms return copies
EBImageBioconductor: BiocManager::install("EBImage")4.54.0 (Bioconductor 3.23, R 4.6)LGPLNone listedImage class with numeric .Data array and colormode slot; multiple frames
imagerCRAN: install.packages("imager")1.0.8 (published 2025-12-23)LGPL-3fftw3, libtiff, X11cimg four-dimensional array: x, y, z (depth/time), c (colour)

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Image Processing in R: magick, EBImage and imager

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →