[171cba]: / 4x / reference / NumFoci.py

Download this file

135 lines (80 with data), 3.4 kB

  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
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import os
import numpy as np
import skimage as ski
from skimage import io, filter, color, exposure, morphology, feature, draw, measure, transform
import matplotlib
%matplotlib inline
matplotlib.rcParams["figure.figsize"] = (16, 10)
# <codecell>
l = os.listdir("../data")
print l[6]
qstain = np.array([[.26451728, .5205347, .81183386], [.9199094, .29797825, .25489032], [.28947765, .80015373, .5253158]])
# <codecell>
A = io.imread("../data/" + l[5])
io.imshow(A)
# <codecell>
#B = exposure.adjust_sigmoid(filter.gaussian_filter(A[:, :, 0], 19), cutoff=.45, gain=15)
B = exposure.adjust_sigmoid(
filter.gaussian_filter(
exposure.rescale_intensity(
color.separate_stains(
A,
np.linalg.inv(qstain)),
out_range=(0, 1))[:, :, 1],
29),
cutoff=.35, gain=20)
io.imshow(B)
# <codecell>
#b = morphology.remove_small_objects(filter.threshold_adaptive(filter.gaussian_filter(exposure.adjust_sigmoid(A[:,:,1]), 31), 501, offset=-0.05), 2000)
C = morphology.remove_small_objects(
filter.threshold_adaptive(B, 301, offset=-0.025),
4000)
#io.imshow(morphology.binary_closing(np.logical_or(morphology.binary_dilation(C, morphology.disk(11)), b), morphology.disk(31)))
io.imshow(C)
#io.imshow(exposure.adjust_sigmoid(A[:, :, 1]))
# <codecell>
io.imshow(A)
# <codecell>
d = ski.img_as_float(color.separate_stains(A, np.linalg.inv(qstain)))
dd = exposure.adjust_sigmoid(filter.gaussian_filter(exposure.rescale_intensity(d[:, :, 0] + d[:, :, 2], out_range=(0, 1)), 21), gain=7, cutoff=0.6)
ddd = morphology.remove_small_objects(filter.threshold_adaptive(dd, 301, offset=-0.06), 2000)
io.imshow(morphology.binary_erosion(morphology.binary_dilation(ddd, morphology.disk(41)), morphology.disk(21)))
#io.imshow(exposure.rescale_intensity(ski.img_as_float(A[:, :, 1]) + ski.img_as_float(A[:, :, 2]), out_range=(0, 256)))
# <codecell>
e = filter.gaussian_filter(exposure.rescale_intensity(d[:,:,1], out_range=(0, 1)), 31)
#io.imshow(filter.gaussian_filter(e, 21))
#print np.mean(e)
plt.plot(exposure.histogram(e)[1], exposure.histogram(e)[0])
# <codecell>
io.imshow(filter.threshold_adaptive(e, 301, offset=0.025))
# <codecell>
io.imshow(A)
# <codecell>
from skimage import data
ihc = data.immunohistochemistry()
ihc_hdx = color.separate_stains(ihc, color.hdx_from_rgb)
ihc_rgb = color.combine_stains(ihc_hdx, color.rgb_from_hdx)
io.imshow(ihc_hdx[:,:,0])
# <codecell>
print [[0.644211, .835*0.716556, 0.266844], [0.092789, .835*0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]
io.imshow(color.separate_stains(A,
np.linalg.inv([[0.644211, 0.716556, 0.266844], [0.092789, 0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]))[:, :, 2])
# <codecell>
qstain = np.array([[.26451728, .5205347, .81183386], [.9199094, .29797825, .25489032], [.28947765, .80015373, .5253158]])
qfrompaper = np.array([[0.644211, .835*0.716556, 0.266844], [0.092789, .835*0.954111, 0.283111], [0.75919851748933231, 0.085468001712004443, 0.92121791197468583]])
aa = io.imread("/Users/qcaudron/Desktop/he copy.jpg")
ab = color.separate_stains(A,
np.linalg.inv(qstain))
ac = color.combine_stains(ab,
(qstain))
io.imshow(ab[1000:2000, :1000, 1])
#print np.max(ab[:,:,2])
# <codecell>
np.sum(q**2, axis=1)
# <codecell>
# <codecell>
print (color.rgb_from_hed)
print color.hed_from_rgb