This repository was archived by the owner on May 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathexample.py
More file actions
74 lines (62 loc) · 2.46 KB
/
example.py
File metadata and controls
74 lines (62 loc) · 2.46 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
import staintools
import datetime
# Set up
METHOD = 'vahadane'
STANDARDIZE_BRIGHTNESS = True
RESULTS_DIR = './results ' + str(datetime.datetime.now()) + '/'
# Read the images
i1 = staintools.read_image("./data/i1.png")
i2 = staintools.read_image("./data/i2.png")
i3 = staintools.read_image("./data/i3.png")
i4 = staintools.read_image("./data/i4.png")
i5 = staintools.read_image("./data/i5.png")
# Plot
images = [i1, i2, i3, i4, i5]
titles = ["Target"] + ["Original"] * 4
staintools.plot_image_list(images, width=5, title_list=titles,
save_name=RESULTS_DIR + 'original-images.png', show=0)
# =========================
# Brightness standardization
# (Can skip but can help with tissue mask detection)
# =========================
if STANDARDIZE_BRIGHTNESS:
# Standardize brightness
i1 = staintools.LuminosityStandardizer.standardize(i1)
i2 = staintools.LuminosityStandardizer.standardize(i2)
i3 = staintools.LuminosityStandardizer.standardize(i3)
i4 = staintools.LuminosityStandardizer.standardize(i4)
i5 = staintools.LuminosityStandardizer.standardize(i5)
# Plot
images = [i1, i2, i3, i4, i5]
titles = ["Target standardized"] + ["Original standardized"] * 4
staintools.plot_image_list(images, width=5, title_list=titles,
save_name=RESULTS_DIR + 'original-images-standardized.png', show=0)
# ===================
# Stain normalization
# ===================
# Normalize to stain of first image
normalizer = staintools.StainNormalizer(method=METHOD)
normalizer.fit(i1)
i2_normalized = normalizer.transform(i2)
i3_normalized = normalizer.transform(i3)
i4_normalized = normalizer.transform(i4)
i5_normalized = normalizer.transform(i5)
# Plot
images = [i1, i2_normalized, i3_normalized, i4_normalized, i5_normalized]
titles = ["Target"] + ["Stain normalized"] * 4
staintools.plot_image_list(images, width=5, title_list=titles,
save_name=RESULTS_DIR + 'stain-normalized-images.png', show=0)
# ==================
# Stain augmentation
# ==================
# Augment the first image
augmentor = staintools.StainAugmentor(method=METHOD, sigma1=0.4, sigma2=0.4)
augmentor.fit(i1)
augmented_images = []
for _ in range(10):
augmented_image = augmentor.pop()
augmented_images.append(augmented_image)
# Plot
titles = ["Augmented"] * 10
staintools.plot_image_list(augmented_images, width=5, title_list=titles,
save_name=RESULTS_DIR + 'stain-augmented-images.png', show=0)