|
a |
|
b/docs/Measurements.rst |
|
|
1 |
.. _Measurements_page: |
|
|
2 |
|
|
|
3 |
*********************************** |
|
|
4 |
Measurements as performed in python |
|
|
5 |
*********************************** |
|
|
6 |
|
|
|
7 |
Amount of Tissue |
|
|
8 |
================ |
|
|
9 |
|
|
|
10 |
.. code-block:: python |
|
|
11 |
|
|
|
12 |
def QuantCore(self, image, filename, save=False): |
|
|
13 |
image = gaussian(rgb2gray(image), sigma=2) |
|
|
14 |
thresh = threshold_triangle(image[image > 0]) |
|
|
15 |
binary = np.logical_and(image < thresh, image > 0) |
|
|
16 |
wholeCore = np.sum(binary) |
|
|
17 |
if save: |
|
|
18 |
self.info.emit("Saving - " + filename + '_core.tiff') |
|
|
19 |
imagesave = Image.fromarray(binary) |
|
|
20 |
imagesave.save(self.inputpath+os.sep+filename + '_core.tiff') |
|
|
21 |
return wholeCore |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
Amount of Signal |
|
|
25 |
================ |
|
|
26 |
|
|
|
27 |
.. code-block:: python |
|
|
28 |
|
|
|
29 |
def QuantStain(self, image, filename, save=False): |
|
|
30 |
img_hsv = rgb2hsv(image) |
|
|
31 |
img_hue = img_hsv[:, :, 0] |
|
|
32 |
image_sat = img_hsv[:, :, 1] |
|
|
33 |
hue = np.logical_and(img_hue > 0.02, img_hue < 0.10) # BROWN PIXELS BETWEEN 0.02 and 0.10 |
|
|
34 |
if self.threshold: |
|
|
35 |
stain = np.logical_and(hue, image_sat > self.threshold) # USER DEFINED MINIMUM SATURATION THRESHOLD |
|
|
36 |
else: |
|
|
37 |
print("Defult threshold") |
|
|
38 |
stain = np.logical_and(hue, image_sat > 0.79) # DEFAULT SATURATION THRESHOLD APPLIED IF NO USER INPUT |
|
|
39 |
self.current_image = stain[::10, ::10].astype(float) # SHOW A LOW RESOLUTION MASK AS A FIGURE |
|
|
40 |
self.figures.emit() |
|
|
41 |
if save: |
|
|
42 |
self.info.emit("Saving - " + filename+'_stain.tiff') # SAVE A FIGURE IF REQUIRED |
|
|
43 |
imagesave = Image.fromarray(stain) |
|
|
44 |
imagesave.save(self.inputpath+os.sep+filename+'_stain.tiff') |
|
|
45 |
stint = np.copy(image) |
|
|
46 |
stint = exposure.rescale_intensity(stint, out_range=(0, 255)) |
|
|
47 |
stint[stain == 0] = 0 # array with only the stained pixels |
|
|
48 |
stint = color.rgb2gray(stint) # convert to greyscale |
|
|
49 |
stint = np.ravel(stint) # flatten image array |
|
|
50 |
stint = stint[stint != 0] # remove all zeros |
|
|
51 |
stint_mean = stint.mean() |
|
|
52 |
stint_std = stint.std() |
|
|
53 |
stained = np.sum(stain) |
|
|
54 |
return stained, stint_mean, stint_std |