Adapted from: https://www.bioconductor.org/packages/release/bioc/vignettes/EBImage/inst/doc/EBImage-introduction.html

On Ubuntu install requires sudo apt install r-cran-fftwtools from marutter’s ppa

install.packages("BiocManager")
BiocManager::install("EBImage")
library(EBImage)

Reading

nuclei_file <- system.file("images", "nuclei.tif", package="EBImage")
nuclei_img <- readImage(nuclei_file)
nuclei_img

Display

plot(nuclei_img)
display(nuclei_img)

Cropping

nuclei_img_cropped <- nuclei_img[200:300, 350:450, 1]
display(nuclei_img_cropped)
nuclei_img = nuclei_img[,,1]
nuclei_img

Thresholding

nuclei_img[220:225, 220:225]
nuclei_thresh <- nuclei_img > 0.5
display(nuclei_thresh)
nuclei_thresh <- nuclei_img > 0.1
display(nuclei_thresh)
threshold <- otsu(nuclei_img)
nuclei_thresh <- nuclei_img > threshold
display(nuclei_thresh)

Image segmentation

nuclei_segmented <- bwlabel(nuclei_thresh)
nuclei_segmented
nuclei_segmented@.Data[1:15, 1:15]
display(colorLabels(nuclei_segmented))

Counting objects

max(nuclei_segmented)

Measuring

computeFeatures.shape(nuclei_segmented)
computeFeatures(nuclei_segmented, nuclei_img)

Conclusions