-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEBImage_26BL.R
153 lines (124 loc) · 4.98 KB
/
EBImage_26BL.R
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
############################# CD3 ###############################
#cell surface CD4 receptor image
CD3_cell_surface = data$`26BL`$CD3
#hist(CD_8a_cell_surface)
display(CD3_cell_surface)
CD3_cell_surface.norm = normalize(CD3_cell_surface, inputRange = quantile(CD3_cell_surface, c(0,0.99)))
#hist(CD4_cell_surface.norm)
CD3_cell_surface.norm.blur = gblur(CD3_cell_surface.norm, sigma = 1)
display(CD3_cell_surface.norm.blur)
#cell segentation
cells = rgbImage(green = 1.5*CD3_cell_surface.norm.blur)
#cell surface mask
#get cells that stand out of the moving background window
cmask = thresh(CD3_cell_surface.norm.blur, w=7, h=7, offset=0.05)
#get rid of noises
cmask = opening(cmask, makeBrush(3, shape='disc'))
#apply watershed to further segment cells
cmask = watershed(distmap(cmask), 2)
display(CD3_cell_surface.norm.blur)
display(colorLabels(cmask))
#segment regions with seeds = cmask
ctmask = propagate(CD4_cell_surface.norm.blur, seeds = cmask)
display(colorLabels(ctmask))
#display(paintObjects(cmask, CD4_cell_surface.norm.blur, col = "#ff00ff"))
#paint outline of cell mask on image of cells
segmented = paintObjects(ctmask, cells, col = "#ff00ff")
display(cells)
display(segmented)
############################# H3 ###############################
#histone3 marker image
histone = data$`26BL`$`Histone-H3`
#hist(CD_8a_cell_surface)
display(histone)
histone.norm = normalize(histone, inputRange = quantile(histone, c(0,0.99)))
#hist(CD4_cell_surface.norm)
histone.norm.blur = gblur(histone.norm, sigma = 1)
display(histone.norm.blur)
#cell segentation
cells = rgbImage(green = 1.5*histone.norm.blur)
#cell mask
#get cells that stand out of the moving background window
cmask = thresh(histone.norm.blur, w=7, h=7, offset=0.05)
#get rid of noises
cmask = opening(cmask, makeBrush(3, shape='disc'))
#apply watershed to further segment cells
cmask = watershed(distmap(cmask), 2)
display(histone.norm.blur)
display(colorLabels(cmask))
#segment regions with seeds = cmask
ctmask = propagate(histone.norm.blur, seeds = cmask)
display(colorLabels(ctmask))
#display(paintObjects(cmask, CD4_cell_surface.norm.blur, col = "#ff00ff"))
#paint outline of cell mask on image of cells
segmented = paintObjects(ctmask, cells, col = "#ff00ff")
display(cells)
display(segmented)
############################ CD 20 #############################
#histone3 marker image
CD20 = data$`26BL`$CD20
#hist(CD_8a_cell_surface)
display(CD20)
CD20.norm = normalize(CD20, inputRange = quantile(CD20, c(0,0.99)))
#hist(CD4_cell_surface.norm)
CD20.norm.blur = gblur(CD20.norm, sigma = 1)
display(CD20.norm.blur)
#cell segentation
cells = rgbImage(green = 1.5*CD20.norm.blur)
#cell mask
#get cells that stand out of the moving background window
cmask = thresh(CD20.norm.blur, w=7, h=7, offset=0.05)
#get rid of noises
cmask = opening(cmask, makeBrush(3, shape='disc'))
#apply watershed to further segment cells
cmask = watershed(distmap(cmask), 2)
display(CD20.norm.blur)
display(colorLabels(cmask))
#segment regions with seeds = cmask
ctmask = propagate(CD20.norm.blur, seeds = cmask)
display(colorLabels(ctmask))
#display(paintObjects(cmask, CD4_cell_surface.norm.blur, col = "#ff00ff"))
#paint outline of cell mask on image of cells
segmented = paintObjects(ctmask, cells, col = "#ff00ff")
display(cells)
display(segmented)
############################# CD4 ###############################
#cell surface CD4 receptor image
CD3_cell_surface = data$`26BL`$CD3
#hist(CD_8a_cell_surface)
display(CD3_cell_surface)
CD3_cell_surface.norm = normalize(CD3_cell_surface, inputRange = quantile(CD3_cell_surface, c(0,0.99)))
#hist(CD4_cell_surface.norm)
CD3_cell_surface.norm.blur = gblur(CD3_cell_surface.norm, sigma = 1)
display(CD3_cell_surface.norm.blur)
#histone3 marker image
img_histone = data$`26BL`$`Histone-H3` # get marker CD3 from sample 26BL
#hist(img_histone)
display(img_histone)
#display(img_histone, method = "raster")
# trim above 99% and use normalize() to re-scale to [0,1]
img_histone.norm = normalize(img_histone,inputRange = quantile(img_histone,c(0,0.99)))
#hist(img_histone.norm)
display(img_histone.norm)
img_histone.norm.blur = gblur(img_histone.norm, sigma = 1)
display(img_histone.norm.blur)
#cell segentation
cells = rgbImage(green = 1.5*CD3_cell_surface.norm.blur, blue = 1.5*img_histone.norm.blur)
#nuclei mask
nmask = thresh(img_histone.norm.blur, w=5, h=5, offset=0.05)
nmask = opening(nmask, makeBrush(5, shape='disc'))
nmask = watershed(distmap(nmask), 2)
display(img_histone.norm.blur)
display(colorLabels(nmask))
#cell surface(regions) mask
#CD3_cell_surface.norm.blur = gblur(CD3_cell_surface, sigma = 1)
cmask = opening(CD4_cell_surface.norm.blur>0.1, makeBrush(5, shape = 'disc'))
display(cmask)
cmask = propagate(CD4_cell_surface.norm.blur, seeds = nmask, mask = cmask)
display(CD3_cell_surface.norm.blur>0.1)
display(colorLabels(cmask))
#display(paintObjects(cmask, CD4_cell_surface.norm.blur, col = "#ff00ff"))
#paint outline of cell mask on image of cells
segmented = paintObjects(cmask, cells, col = "#ff00ff")
display(cells)
display(segmented)