knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" )
Autofluorescence is a long-standing problem that has hindered fluorescence microscopy image analysis. To address this, we have developed a method that identifies and removes autofluorescent signals from multi-channel images post acquisition.
library(devtools) devtools::install_github("ellispatrick/AFremover")
library(AFremover) set.seed(51773) ## Read in images. imageFile1 = system.file("extdata","ImageB.CD3.tif", package = "AFremover") imageFile2 = system.file("extdata","ImageB.CD11c.tif", package = "AFremover") im1 <- EBImage::readImage(imageFile1) im2 <- EBImage::readImage(imageFile2) ## Rescale the images. im1 = im1/max(im1) im2 = im2/max(im2) combined <- EBImage::rgbImage(green=sqrt(im1), red=sqrt(im2)) EBImage::display(combined, all = TRUE, method = 'raster') ## Create masks using EBImage. # Find tissue area tissue1 = im1 > 2*min(im1) tissue2 = im2 > 2*min(im2) # Calculate thresholds imThreshold1 <- mean(im1[tissue1]) + 2*sd(im1[tissue1]) imThreshold2 <- mean(im2[tissue2]) + 2*sd(im2[tissue2]) # Calculate masks. mask1 <- EBImage::bwlabel(im1 > imThreshold1) mask2 <- EBImage::bwlabel(im2 > imThreshold2) ## Calculate intersection mask mask <- intMask(mask1,mask2) ## Calculate textural features. df <- afMeasure(im1, im2, mask) ## Alternatively ## Correlation only # afMask <- afIdentify(mask, df, minSize = 100, maxSize = Inf, corr = 0.6) ## Clustering with given k # afMask <- afIdentify(mask, df, minSize = 100, maxSize = Inf, k = 6) ## Clustering with estimated k. afMask <- afIdentify(mask, df, minSize = 100, maxSize = Inf, k = 20, kAuto = TRUE) ## Remove autofluorescence from images (Use ImageJ for halo removal) im1AFRemoved <- im1 im2AFRemoved <- im2 im1AFRemoved[afMask != 0] <- 0 im2AFRemoved[afMask != 0] <- 0 combinedRemoved <- EBImage::rgbImage(green = sqrt(im1AFRemoved), red = sqrt(im2AFRemoved)) img_comb = EBImage::combine(combined, combinedRemoved) EBImage::display(img_comb, all = TRUE, method = 'raster',nx = 2) ## Or ## Exclude AF ROIs exclude1 = unique(mask1[afMask>0]) mask1Removed = mask1 mask1Removed[mask1Removed%in%exclude1] = 0 exclude2 = unique(mask2[afMask>0]) mask2Removed = mask2 mask2Removed[mask2Removed%in%exclude2] = 0 ## OR ## A more agressive strategy to remove autofluorescence from images as an alternative to the halo removal implemented in ImageJ im1AFRemovedv2 <- im1 im2AFRemovedv2 <- im2 im1AFRemovedv2[!mask1%in%mask1Removed|!mask2%in%mask2Removed] <- 0 im2AFRemovedv2[!mask1%in%mask1Removed|!mask2%in%mask2Removed] <- 0 combinedRemovedv2 <- EBImage::rgbImage(green = sqrt(im1AFRemovedv2), red = sqrt(im2AFRemovedv2)) img_combv2 = EBImage::combine(combined, combinedRemovedv2) EBImage::display(img_combv2, all = TRUE, method = 'raster',nx = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.