-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
122 lines (79 loc) · 3 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# AFidR
Autofluorescence is a long-standing problem that has hindered fluorescence microscopy image analysis. To address this, we have developed a method that identifies and can exclude autofluorescent signals from multi-channel images post acquisition.
## Installation
``` r
library(devtools)
devtools::install_github("ellispatrick/AFidR")
```
## A quick example
```{r, eval = TRUE}
library(AFidR)
set.seed(51773)
## Read in images.
imageFile1 = system.file("extdata","ImageB.CD3.tif", package = "AFidR")
imageFile2 = system.file("extdata","ImageB.CD11c.tif", package = "AFidR")
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)
## Exclude autofluorescence from images (Use ImageJ for halo removal)
im1AFExcluded <- im1
im2AFExcluded <- im2
im1AFExcluded[afMask != 0] <- 0
im2AFExcluded[afMask != 0] <- 0
combinedExcluded <- EBImage::rgbImage(green = sqrt(im1AFExcluded), red = sqrt(im2AFExcluded))
img_comb = EBImage::combine(combined, combinedExcluded)
EBImage::display(img_comb, all = TRUE, method = 'raster',nx = 2)
## Or
## Exclude AF ROIs
exclude1 = unique(mask1[afMask>0])
mask1Excluded = mask1
mask1Excluded[mask1Excluded%in%exclude1] = 0
exclude2 = unique(mask2[afMask>0])
mask2Excluded = mask2
mask2Excluded[mask2Excluded%in%exclude2] = 0
## OR
## A more agressive strategy to exclude autofluorescence from images as an alternative to the halo removal implemented in ImageJ
im1AFExcludedv2 <- im1
im2AFExcludedv2 <- im2
im1AFExcludedv2[!mask1%in%mask1Excluded|!mask2%in%mask2Excluded] <- 0
im2AFExcludedv2[!mask1%in%mask1Excluded|!mask2%in%mask2Excluded] <- 0
combinedExcludedv2 <- EBImage::rgbImage(green = sqrt(im1AFExcludedv2), red = sqrt(im2AFExcludedv2))
img_combv2 = EBImage::combine(combined, combinedExcludedv2)
EBImage::display(img_combv2, all = TRUE, method = 'raster',nx = 2)
```