@@ -10,13 +10,13 @@ def __init__(self):
1010 super ().__init__ ()
1111
1212 self .HERef = np .array ([[0.5626 , 0.2159 ],
13- [0.7201 , 0.8012 ],
14- [0.4062 , 0.5581 ]])
13+ [0.7201 , 0.8012 ],
14+ [0.4062 , 0.5581 ]])
1515 self .maxCRef = np .array ([1.9705 , 1.0308 ])
1616
1717 def __convert_rgb2od (self , I , Io = 240 , beta = 0.15 ):
1818 # calculate optical density
19- OD = - np .log ((I .astype (float )+ 1 ) / Io )
19+ OD = - np .log ((I .astype (float ) + 1 ) / Io )
2020
2121 # remove transparent pixels
2222 ODhat = OD [~ np .any (OD < beta , axis = 1 )]
@@ -26,22 +26,22 @@ def __convert_rgb2od(self, I, Io=240, beta=0.15):
2626 def __find_HE (self , ODhat , eigvecs , alpha ):
2727 #project on the plane spanned by the eigenvectors corresponding to the two
2828 # largest eigenvalues
29- That = ODhat .dot (eigvecs [:,1 :3 ])
29+ That = ODhat .dot (eigvecs [:, 1 :3 ])
3030
31- phi = np .arctan2 (That [:,1 ],That [:,0 ])
31+ phi = np .arctan2 (That [:, 1 ], That [:, 0 ])
3232
3333 minPhi = np .percentile (phi , alpha )
34- maxPhi = np .percentile (phi , 100 - alpha )
34+ maxPhi = np .percentile (phi , 100 - alpha )
3535
36- vMin = eigvecs [:,1 :3 ].dot (np .array ([(np .cos (minPhi ), np .sin (minPhi ))]).T )
37- vMax = eigvecs [:,1 :3 ].dot (np .array ([(np .cos (maxPhi ), np .sin (maxPhi ))]).T )
36+ vMin = eigvecs [:, 1 :3 ].dot (np .array ([(np .cos (minPhi ), np .sin (minPhi ))]).T )
37+ vMax = eigvecs [:, 1 :3 ].dot (np .array ([(np .cos (maxPhi ), np .sin (maxPhi ))]).T )
3838
3939 # a heuristic to make the vector corresponding to hematoxylin first and the
4040 # one corresponding to eosin second
4141 if vMin [0 ] > vMax [0 ]:
42- HE = np .array ((vMin [:,0 ], vMax [:,0 ])).T
42+ HE = np .array ((vMin [:, 0 ], vMax [:, 0 ])).T
4343 else :
44- HE = np .array ((vMax [:,0 ], vMin [:,0 ])).T
44+ HE = np .array ((vMax [:, 0 ], vMin [:, 0 ])).T
4545
4646 return HE
4747
@@ -55,7 +55,7 @@ def __find_concentration(self, OD, HE):
5555 return C
5656
5757 def __compute_matrices (self , I , Io , alpha , beta ):
58- I = I .reshape ((- 1 ,3 ))
58+ I = I .reshape ((- 1 , 3 ))
5959
6060 OD , ODhat = self .__convert_rgb2od (I , Io = Io , beta = beta )
6161
@@ -67,7 +67,7 @@ def __compute_matrices(self, I, Io, alpha, beta):
6767 C = self .__find_concentration (OD , HE )
6868
6969 # normalize stain concentrations
70- maxC = np .array ([np .percentile (C [0 ,:], 99 ), np .percentile (C [1 ,:],99 )])
70+ maxC = np .array ([np .percentile (C [0 , :], 99 ), np .percentile (C [1 , :],99 )])
7171
7272 return HE , C , maxC
7373
@@ -81,7 +81,7 @@ def normalize(self, I, Io=240, alpha=1, beta=0.15, stains=True):
8181 ''' Normalize staining appearence of H&E stained images
8282
8383 Example use:
84- see test .py
84+ see example .py
8585
8686 Input:
8787 I: RGB input image
@@ -97,7 +97,7 @@ def normalize(self, I, Io=240, alpha=1, beta=0.15, stains=True):
9797 Macenko et al., ISBI 2009
9898 '''
9999 h , w , c = I .shape
100- I = I .reshape ((- 1 ,3 ))
100+ I = I .reshape ((- 1 , 3 ))
101101
102102 HE , C , maxC = self .__compute_matrices (I , Io , alpha , beta )
103103
@@ -114,11 +114,11 @@ def normalize(self, I, Io=240, alpha=1, beta=0.15, stains=True):
114114
115115 if stains :
116116 # unmix hematoxylin and eosin
117- H = np .multiply (Io , np .exp (np .expand_dims (- self .HERef [:,0 ], axis = 1 ).dot (np .expand_dims (C2 [0 ,:], axis = 0 ))))
117+ H = np .multiply (Io , np .exp (np .expand_dims (- self .HERef [:, 0 ], axis = 1 ).dot (np .expand_dims (C2 [0 , :], axis = 0 ))))
118118 H [H > 255 ] = 255
119119 H = np .reshape (H .T , (h , w , c )).astype (np .uint8 )
120120
121- E = np .multiply (Io , np .exp (np .expand_dims (- self .HERef [:,1 ], axis = 1 ).dot (np .expand_dims (C2 [1 ,:], axis = 0 ))))
121+ E = np .multiply (Io , np .exp (np .expand_dims (- self .HERef [:, 1 ], axis = 1 ).dot (np .expand_dims (C2 [1 , :], axis = 0 ))))
122122 E [E > 255 ] = 255
123123 E = np .reshape (E .T , (h , w , c )).astype (np .uint8 )
124124
0 commit comments