Introduction to EBImage, an image processing and analysis toolkit for R

Similar documents
Introduction to EBImage, an image processing and analysis toolkit for R

EBImage. October 25, Description These following functions are deprecated and will be defunct in the next Bioconductor release.

EBImage. April 20, Blurring images

Package EBImage. August 17, 2013

Introduction to EBImage, an image processing and analysis toolkit for R

Using image data for statistical analysis and modeling Wolfgang Huber & Gregoire Pau EMBL

Package EBImage. October 12, 2016

Package EBImage. November 18, 2017

Package EBImage. October 9, 2015

[ ] Review. Edges and Binary Images. Edge detection. Derivative of Gaussian filter. Image gradient. Tuesday, Sept 16

CS443: Digital Imaging and Multimedia Binary Image Analysis. Spring 2008 Ahmed Elgammal Dept. of Computer Science Rutgers University

Introduction. Computer Vision & Digital Image Processing. Preview. Basic Concepts from Set Theory

Morphological Image Processing

EE795: Computer Vision and Intelligent Systems

Biomedical Image Analysis. Mathematical Morphology

SECTION 5 IMAGE PROCESSING 2

Digital Image Processing

C E N T E R A T H O U S T O N S C H O O L of H E A L T H I N F O R M A T I O N S C I E N C E S. Image Operations II

EUROPEAN COMPUTER DRIVING LICENCE / INTERNATIONAL COMPUTER DRIVING LICENCE IMAGE EDITING

ECG782: Multidimensional Digital Signal Processing

Previously. Edge detection. Today. Thresholding. Gradients -> edges 2/1/2011. Edges and Binary Image Analysis

CITS 4402 Computer Vision

Edges and Binary Images

JAVA DIP - OPEN SOURCE LIBRARIES

Babu Madhav Institute of Information Technology Years Integrated M.Sc.(IT)(Semester - 7)

Edges and Binary Image Analysis. Thurs Jan 26 Kristen Grauman UT Austin. Today. Edge detection and matching

Image Processing. Bilkent University. CS554 Computer Vision Pinar Duygulu

EXAM SOLUTIONS. Image Processing and Computer Vision Course 2D1421 Monday, 13 th of March 2006,

EE 584 MACHINE VISION

Biometrics Technology: Image Processing & Pattern Recognition (by Dr. Dickson Tong)

Lecture: Segmentation I FMAN30: Medical Image Analysis. Anders Heyden

Image Processing Fundamentals. Nicolas Vazquez Principal Software Engineer National Instruments

Detection of Edges Using Mathematical Morphological Operators

A Visual Programming Environment for Machine Vision Engineers. Paul F Whelan

Edges and Binary Image Analysis April 12 th, 2018

Anno accademico 2006/2007. Davide Migliore

Texture. Frequency Descriptors. Frequency Descriptors. Frequency Descriptors. Frequency Descriptors. Frequency Descriptors

morphology on binary images

Fundamentals of Digital Image Processing

ECG782: Multidimensional Digital Signal Processing

PPKE-ITK. Lecture

BCC Textured Wipe Animation menu Manual Auto Pct. Done Percent Done

xv Programming for image analysis fundamental steps

EECS490: Digital Image Processing. Lecture #17

BCC Linear Wipe. When the Invert Wipe Checkbox is selected, the alpha channel created by the wipe inverts.

FISHalyseR Automated fluorescence in situ hybridisation quantification in R

Binary Image Analysis. Binary Image Analysis. What kinds of operations? Results of analysis. Useful Operations. Example: red blood cell image

CS534 Introduction to Computer Vision Binary Image Analysis. Ahmed Elgammal Dept. of Computer Science Rutgers University

Lab 2. Hanz Cuevas Velásquez, Bob Fisher Advanced Vision School of Informatics, University of Edinburgh Week 3, 2018

Image Processing: Final Exam November 10, :30 10:30

DiaWear. Figure 1: Overall DiaWear System

Extracting Layers and Recognizing Features for Automatic Map Understanding. Yao-Yi Chiang

Chapter 3: Intensity Transformations and Spatial Filtering

CRImage a package for classifying cells and calculating tumour cellularity

Morphological track 1

Counting Particles or Cells Using IMAQ Vision

Getting Started With Images, Video, and Matlab. CSE 6367 Computer Vision Vassilis Athitsos University of Texas at Arlington

Robbery Detection Camera

COMPUTER AND ROBOT VISION

User Guide Belltech Systems, LLC

Calibrated Image Acquisition for Multi-view 3D Reconstruction

International Journal of Advance Engineering and Research Development. Applications of Set Theory in Digital Image Processing

Robust Zero Watermarking for Still and Similar Images Using a Learning Based Contour Detection

Morphological Image Algorithms

Quick Guide for Photoshop CC Basics April 2016 Training:

Intensity Transformation and Spatial Filtering

Morphological Image Processing

Disease Prediction of Paddy Crops Using Data Mining and Image Processing Techniques

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

IT Digital Image ProcessingVII Semester - Question Bank

IMAGE PROCESSING >FILTERS AND EDGE DETECTION FOR COLOR IMAGES UTRECHT UNIVERSITY RONALD POPPE

GIMP WEB 2.0 BADGES. GIMP is all about IT (Images and Text) OPEN GIMP

Ice-Floe Simulation Viewer Tool

VideoandImageProcessing Blockset 2 User s Guide

ECEN 447 Digital Image Processing

Sobel Edge Detection Algorithm

Binary Image Processing. Introduction to Computer Vision CSE 152 Lecture 5

Laboratory of Applied Robotics

Morphological Image Processing

Index C, D, E, F I, J

User Commands convert ( 1 )

Tip: Shift/Control/Alt- will reset entire Photoshop program in case someone has changed settings.

Image processing. Reading. What is an image? Brian Curless CSE 457 Spring 2017

Problem definition Image acquisition Image segmentation Connected component analysis. Machine vision systems - 1

CS4442/9542b Artificial Intelligence II prof. Olga Veksler

Image Processing using LabVIEW. By, Sandip Nair sandipnair.hpage.com

Topic 6 Representation and Description

BCC Multi Stretch Wipe

CS4442/9542b Artificial Intelligence II prof. Olga Veksler

09/11/2017. Morphological image processing. Morphological image processing. Morphological image processing. Morphological image processing (binary)

BOXOFT Image to PDF s allow you scans paper documents and automatically s them as PDF attachments using your existing software

Introduction to Video and Image Processing

Identifying and Reading Visual Code Markers

CS 5540 Spring 2013 Assignment 3, v1.0 Due: Apr. 24th 11:59PM

Digital Image Processing COSC 6380/4393

Video and Image Processing Blockset 2 User s Guide

Computer Vision 2. SS 18 Dr. Benjamin Guthier Professur für Bildverarbeitung. Computer Vision 2 Dr. Benjamin Guthier

ECE 172A: Introduction to Intelligent Systems: Machine Vision, Fall Midterm Examination

In this lecture. Background. Background. Background. PAM3012 Digital Image Processing for Radiographers

What will we learn? What is mathematical morphology? What is mathematical morphology? Fundamental concepts and operations

Transcription:

Introduction to EBImage, an image processing and analysis toolkit for R Gregoire Pau, Oleg Sklyar, Wolfgang Huber gpau@ebi.ac.uk March 30, 2012 Contents 1 Reading/displaying/writing images 1 2 Image objects and matrices 3 3 Spatial transformations 4 4 Color management 5 5 Image filtering 6 6 Drawing on images 7 7 Morphological operations 8 8 Segmentation 9 9 Object manipulation 11 10 Cell segmentation example 12 1 Reading/displaying/writing images The package EBImage is loaded by the following command. > library("ebimage") The function readimage is able to read images from files or URLs. The supported image formats depend on the capabilities of the underlying ImageMagick library. > f = system.file("images", "lena.gif", package="ebimage") > lena = readimage(f) Images can be displayed using the function display. Pixel intensities should range from 0 (black) to 1 (white). 1

Figure 1: lena, lenac > display(lena) Color images or images with multiple frames can also be read with readimage. > lenac = readimage(system.file("images", "lena-color.png", package="ebimage")) > display(lenac) > nuc = readimage(system.file('images', 'nuclei.tif', package='ebimage')) > display(nuc) Figure 2: nuc Images can be written with writeimage. The file format is deduced from the file name extension. This is useful to convert image formats, here from PNG format to JPEG format. > writeimage(lena, 'lena.jpeg', quality=85) > writeimage(lenac, 'lenac.jpeg', quality=85) 2

2 Image objects and matrices The package EBImage uses the class Image to store and process images. Images are stored as multi-dimensional arrays containing the pixel intensities. All EBImage functions are also able to work with matrices and arrays. > print(lena) Image colormode: Grayscale storage.mode: double dim: 512 512 nb.total.frames: 1 nb.render.frames: 1 imagedata(object)[1:5,1:6]: [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.5372549 0.5372549 0.5372549 0.5372549 0.5372549 0.5490196 [2,] 0.5372549 0.5372549 0.5372549 0.5372549 0.5372549 0.5490196 [3,] 0.5372549 0.5372549 0.5372549 0.5372549 0.5372549 0.5137255 [4,] 0.5333333 0.5333333 0.5333333 0.5333333 0.5333333 0.5098039 [5,] 0.5411765 0.5411765 0.5411765 0.5411765 0.5411765 0.5333333 As matrices, images can be manipulated with all R mathematical operators. This includes + to control the brightness of an image, * to control the contrast of an image or ^ to control the gamma correction parameter. > lena1 = lena+0.5 > lena2 = 3*lena > lena3 = (0.2+lena)^3 Figure 3: lena, lena1, lena2, lena3 Others operators include [ to crop images, < to threshold images or t to transpose images. > lena4 = lena[299:376, 224:301] > lena5 = lena>0.5 > lena6 = t(lena) > print(median(lena)) [1] 0.3803922 Images with multiple frames are created using combine which merges images. > lenacomb = combine(lena, lena*2, lena*3, lena*4) > display(lenacomb) 3

Figure 4: lena, lena4, lena5, lena6 Figure 5: lenacomb 3 Spatial transformations Specific spatial image transformations are done with the functions resize, rotate, translate and the functions flip and flop to reflect images. > lena7 = rotate(lena, 30) > lena8 = translate(lena, c(40, 70)) > lena9 = flip(lena) Figure 6: lena, lena7, lena8, lena9 4

4 Color management The class Image extends the base class array and uses the colormode slot to store how the color information of the multi-dimensional data should be handled. As an example, the color image lenac is a 512x512x3 array, with a colormode slot equals to Color. The object is understood as a color image by EBImage functions. > print(lenac) Image colormode: Color storage.mode: double dim: 512 512 3 nb.total.frames: 3 nb.render.frames: 1 imagedata(object)[1:5,1:6,1]: [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.8862745 0.8862745 0.8862745 0.8862745 0.8862745 0.8901961 [2,] 0.8862745 0.8862745 0.8862745 0.8862745 0.8862745 0.8901961 [3,] 0.8745098 0.8745098 0.8745098 0.8745098 0.8745098 0.8901961 [4,] 0.8745098 0.8745098 0.8745098 0.8745098 0.8745098 0.8705882 [5,] 0.8862745 0.8862745 0.8862745 0.8862745 0.8862745 0.8862745 The function colormode can access and change the value of the slot colormode, modifying the rendering mode of an image. In the next example, the Color image lenac with one frame is changed into a Grayscale image with 3 frames, corresponding to the red, green and blue channels. The function colormode does not change the content of the image but changes only the way the image is rendered by EBImage. > colormode(lenac) = Grayscale > display(lenac) Figure 7: lenac, rendered as a Color image and as a Grayscale image with 3 frames (red channel, green channel, blue channel) The color mode of image lenac is reverted back to Color. > colormode(lenac) = Color The function channel performs colorspace conversion and can convert Grayscale images into Color ones both ways and can extract color channels from Color images. Unlike colormode, channel changes the pixel intensity values of the image. The function rgbimage is able to combine 3 Grayscale images into a Color one. > lenak = channel(lena, 'rgb') > lenak[236:276, 106:146, 1] = 1 > lenak[236:276, 156:196, 2] = 1 > lenak[236:276, 206:246, 3] = 1 > lenab = rgbimage(red=lena, green=flip(lena), blue=flop(lena)) 5

Figure 8: lenak, lenab 5 Image filtering Images can be linearly filtered using filter2. filter2 convolves the image with a matrix filter. Linear filtering is useful to perform low-pass filtering (to blur images, remove noise,...) and high-pass filtering (to detect edges, sharpen images,...). Various filter shapes can be generated using makebrush. > flo = makebrush(21, shape='disc', step=false)^2 > flo = flo/sum(flo) > lenaflo = filter2(lenac, flo) > fhi = matrix(1, nc=3, nr=3) > fhi[2,2] = -8 > lenafhi = filter2(lenac, fhi) 6

Figure 9: Low-pass filtered lenaflo and high-pass filtered lenafhi 6 Drawing on images The function drawtext draws text labels on images. > font = drawfont(weight=600, size=28) > lenatext = drawtext(lena, xy=c(250, 450), labels="lena", font=font, col="white") Figure 10: lenatext 7

7 Morphological operations Binary images are images where the pixels of value 0 constitute the background and the other ones constitute the foreground. These images are subject to several non-linear mathematical operators called morphological operators, able to erode and dilate an image. > ei = readimage(system.file('images', 'shapes.png', package='ebimage')) > ei = ei[110:512,1:130] > display(ei) > kern = makebrush(5, shape='diamond') > eierode = erode(ei, kern) > eidilat = dilate(ei, kern) Figure 11: ei ; eierode ; eidilat 8

8 Segmentation Segmentation consists in extracting objects from an image. The function bwlabel is a simple function able to extract every connected sets of pixels from an image and relabel these sets with a unique increasing integer. bwlabel can be used on binary images and is useful after thresholding. > eilabel = bwlabel(ei) > cat('number of objects=', max(eilabel),'\n') Number of objects= 7 > nuct = nuc[,,1]>0.2 > nuclabel = bwlabel(nuct) > cat('number of nuclei=', max(nuclabel),'\n') Number of nuclei= 74 Figure 12: ei, eilabel/max(eilabel) Figure 13: nuc[,,1], nuclabel/max(nuclabel) Since the images eilabel and nuclabel range from 0 to the number of object they contain (given by max(eilabel) and max(nucabel)), they have to be divided by these number before displaying, in order to fit the [0,1] range needed by display. The grayscale top-bottom gradient observable in eilabel and nuclabel is due to the way bwlabel labels the connected sets, from top-left to bottom-right. Adaptive thresholding consists in comparing the intensity of pixels with their neighbors, where the neighborhood is specified by a filter matrix. The function thresh performs a fast adaptive thresholding of an image with 9

a rectangular window while the combination of filter2 and < allows a finer control. Adaptive thresholding allows a better segmentation when objects are close together. > nuct2 = thresh(nuc[,,1], w=10, h=10, offset=0.05) > kern = makebrush(5, shape='disc') > nuct2 = dilate(erode(nuct2, kern), kern) > nuclabel2 = bwlabel(nuct2) > cat('number of nuclei=', max(nuclabel2),'\n') Number of nuclei= 76 Figure 14: nuc[,,1], nuclabel2/max(nuclabel) 10

9 Object manipulation Objects, defined as sets of pixels with the same unique integer value can be outlined and painted using paintobjects. Some holes are present in objects of nuclabel2 which can be filled using fillhull. > nucgray = channel(nuc[,,1], 'rgb') > nuch1 = paintobjects(nuclabel2, nucgray, col='#ff00ff') > nuclabel3 = fillhull(nuclabel2) > nuch2 = paintobjects(nuclabel3, nucgray, col='#ff00ff') Figure 15: nuch1, nuch2 Objects features like hull features, shape descriptors, moments, centers, texture descriptors are extracted using hullfeatures, moments and getfeatures for more complex features. Nucleus centers are here extracted to obtain nuclei coordinates, which are used to draw the nucleus indexes. > xy = hullfeatures(nuclabel3)[, c('g.x', 'g.y')] > font = drawfont(weight=600, size=16) > nuctext = drawtext(nuch2, xy=xy, labels=as.character(1:nrow(xy)), font=font, col="yellow") 11

Figure 16: Original nuc, segmented nuctext 10 Cell segmentation example This is a complete example of segmentation of cells (nucleus + cell bodies) using the functions described before and the function propagate, able to perform Voronoi-based region segmentation. Images of nuclei and cell bodies are first loaded: > nuc = readimage(system.file('images', 'nuclei.tif', package='ebimage')) > cel = readimage(system.file('images', 'cells.tif', package='ebimage')) > img = rgbimage(green=1.5*cel, blue=nuc) Figure 17: nuc Nuclei are first segmented using thresh, fillhull, bwlabel and opening, which is an erosion followed by a dilatation. > nmask = thresh(nuc, w=10, h=10, offset=0.05) > nmask = opening(nmask, makebrush(5, shape='disc')) > nmask = fillhull(nmask) > nmask = bwlabel(nmask) Cell bodies are segmented using propagate. > ctmask = opening(cel>0.1, makebrush(5, shape='disc')) > cmask = propagate(cel, seeds=nmask, mask=ctmask) 12

Figure 18: cel Figure 19: img Figure 20: nmask/max(nmask) Figure 21: cmask/max(cmask) Cells are outlined using paintobjects and labels are printed using hullfeatures and drawtext. > res = paintobjects(cmask, img, col='#ff00ff') > res = paintobjects(nmask, res, col='#ffff00') 13

> xy = lapply(hullfeatures(cmask), function(hf) hf[, c('g.x', 'g.y')]) > labels = lapply(xy, function(z) as.character(1:nrow(z))) > font = drawfont(weight=600, size=16) > res = drawtext(res, xy=xy, labels=labels, font=font, col="white") Figure 22: Final segmentation res 14