Diff of /4x/reference/NumFoci.py [000000] .. [171cba]

Switch to unified view

a b/4x/reference/NumFoci.py
1
# -*- coding: utf-8 -*-
2
# <nbformat>3.0</nbformat>
3
4
# <codecell>
5
6
import os
7
8
import numpy as np
9
10
import skimage as ski
11
from skimage import io, filter, color, exposure, morphology, feature, draw, measure, transform
12
13
import matplotlib
14
%matplotlib inline
15
matplotlib.rcParams["figure.figsize"] = (16, 10)
16
17
# <codecell>
18
19
l = os.listdir("../data")
20
print l[6]
21
22
qstain = np.array([[.26451728, .5205347, .81183386], [.9199094, .29797825, .25489032], [.28947765, .80015373, .5253158]])
23
24
# <codecell>
25
26
A = io.imread("../data/" + l[5])
27
io.imshow(A)
28
29
# <codecell>
30
31
#B = exposure.adjust_sigmoid(filter.gaussian_filter(A[:, :, 0], 19), cutoff=.45, gain=15)
32
33
34
35
B = exposure.adjust_sigmoid(
36
    filter.gaussian_filter(
37
        exposure.rescale_intensity(
38
            color.separate_stains(
39
                A, 
40
                np.linalg.inv(qstain)), 
41
            out_range=(0, 1))[:, :, 1], 
42
        29), 
43
    cutoff=.35, gain=20)
44
io.imshow(B)
45
46
# <codecell>
47
48
#b = morphology.remove_small_objects(filter.threshold_adaptive(filter.gaussian_filter(exposure.adjust_sigmoid(A[:,:,1]), 31), 501, offset=-0.05), 2000)
49
50
C = morphology.remove_small_objects(
51
    filter.threshold_adaptive(B, 301, offset=-0.025), 
52
    4000)
53
#io.imshow(morphology.binary_closing(np.logical_or(morphology.binary_dilation(C, morphology.disk(11)), b), morphology.disk(31)))
54
io.imshow(C)
55
56
57
#io.imshow(exposure.adjust_sigmoid(A[:, :, 1]))
58
59
# <codecell>
60
61
io.imshow(A)
62
63
# <codecell>
64
65
d = ski.img_as_float(color.separate_stains(A, np.linalg.inv(qstain)))
66
67
dd = exposure.adjust_sigmoid(filter.gaussian_filter(exposure.rescale_intensity(d[:, :, 0] + d[:, :, 2], out_range=(0, 1)), 21), gain=7, cutoff=0.6)
68
69
ddd = morphology.remove_small_objects(filter.threshold_adaptive(dd, 301, offset=-0.06), 2000)
70
71
72
io.imshow(morphology.binary_erosion(morphology.binary_dilation(ddd, morphology.disk(41)), morphology.disk(21)))
73
74
#io.imshow(exposure.rescale_intensity(ski.img_as_float(A[:, :, 1]) + ski.img_as_float(A[:, :, 2]), out_range=(0, 256)))
75
76
# <codecell>
77
78
e = filter.gaussian_filter(exposure.rescale_intensity(d[:,:,1], out_range=(0, 1)), 31)
79
#io.imshow(filter.gaussian_filter(e, 21))
80
#print np.mean(e)
81
plt.plot(exposure.histogram(e)[1], exposure.histogram(e)[0])
82
83
# <codecell>
84
85
io.imshow(filter.threshold_adaptive(e, 301, offset=0.025))
86
87
# <codecell>
88
89
io.imshow(A)
90
91
# <codecell>
92
93
from skimage import data
94
ihc = data.immunohistochemistry()
95
ihc_hdx = color.separate_stains(ihc, color.hdx_from_rgb)
96
ihc_rgb = color.combine_stains(ihc_hdx, color.rgb_from_hdx)
97
98
io.imshow(ihc_hdx[:,:,0])
99
100
# <codecell>
101
102
print [[0.644211, .835*0.716556, 0.266844], [0.092789, .835*0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]
103
io.imshow(color.separate_stains(A, 
104
    np.linalg.inv([[0.644211, 0.716556, 0.266844], [0.092789, 0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]))[:, :, 2])
105
106
107
108
# <codecell>
109
110
qstain = np.array([[.26451728, .5205347, .81183386], [.9199094, .29797825, .25489032], [.28947765, .80015373, .5253158]])
111
qfrompaper = np.array([[0.644211, .835*0.716556, 0.266844], [0.092789, .835*0.954111, 0.283111], [0.75919851748933231, 0.085468001712004443, 0.92121791197468583]])
112
113
aa = io.imread("/Users/qcaudron/Desktop/he copy.jpg")
114
ab = color.separate_stains(A,
115
    np.linalg.inv(qstain))
116
117
ac = color.combine_stains(ab,
118
    (qstain))
119
120
io.imshow(ab[1000:2000, :1000, 1])
121
#print np.max(ab[:,:,2])
122
123
# <codecell>
124
125
np.sum(q**2, axis=1)
126
127
# <codecell>
128
129
130
# <codecell>
131
132
print (color.rgb_from_hed)
133
print color.hed_from_rgb
134