afIdentify: Classifies ROIs as autofuorescent and non-autofluorescent...

Description Usage Arguments Value Examples

Description

Classifies ROIs as autofuorescent and non-autofluorescent based on the measurements obtained by afMeasure.

Usage

1
2
afIdentify(mask, df, minSize = 100, maxSize = Inf, corr = -1,
  kAuto = FALSE, k = 1)

Arguments

mask

A matrix of 0's and 1's describing the mask of the ROIs

df

A data frame generated by afMeasure.

minSize

The minimum ROI size (pixel area) to classify - should be greater than 1.

maxSize

The maximum ROI size (pixel area) to classify.

corr

A correlation cut-off for autofluorescence; all objects above this cut-off within the identified autofluorescence cluster is classified as auofluorescence.

kAuto

Logical to estimate the number of clusters between 3 and a user provided number of clusters defined by 'k'; if TRUE, will perform this estimate.

k

If 'kAuto' = FALSE: number of clusters used when performing k-means; if 'kAuto' = TRUE : maximum number of clusters for estimating an optimal k.

Value

A matrix containing a mask of all autofluorescent objects.

Examples

 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
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)

## Transform the image.
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
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

ellispatrick/AFremover documentation built on June 11, 2019, 7:49 p.m.