-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowPatches
executable file
·86 lines (67 loc) · 2.45 KB
/
showPatches
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
#!/usr/bin/env python
# remove the necessity to have .py extension
from __future__ import print_function, unicode_literals, absolute_import, division
import sys, os
import numpy as np
import matplotlib.pyplot as plt
from csbdeep.utils import Path, download_and_extract_zip_file, plot_some, normalize, normalize_mi_ma
from csbdeep.io import load_training_data, save_tiff_imagej_compatible
option_handle_list = ['--imageNumber']
option_unique_list = ['--info', '--help']
options = {}
for option_handle in option_handle_list:
if option_handle in sys.argv:
options[option_handle[2:]] = sys.argv[sys.argv.index(option_handle) + 1]
else:
options[option_handle[2:]] = None
for option_handle in option_unique_list:
if option_handle in sys.argv:
options[option_handle[2:]] = True
else:
options[option_handle[2:]] = None
if options['info'] != None or options['help'] != None:
print("Function showPatches, this function show plot of pair patches.")
print("Takes the image from 5 to n + 5")
print("USAGE : showPatches [imagePath]")
print("EX: showPatches patch.npz")
print("")
print("options")
exit()
if len(sys.argv) == 1 or not os.path.exists(sys.argv[1]):
raise ValueError("Incorrect path, the first argument must be the image path")
imagePath = sys.argv[1]
#(X_train, Y_train), (X_val,Y_val), axes = load_training_data('data_label.npz', validation_split=0.1, verbose=True)
data = np.load(imagePath)
#training images (180)
x = data['Y'][0]
print('Number of images:', len(data['X']))
print('image size :', x.shape)
# To download :
# import matplotlib.pyplot as plt
# for i in range(5, 10):
# img = normalize(data['X'][i], 0, 100, clip=True)
# plt.imshow(np.squeeze(img))
# plt.savefig("X/img" + str(i) + ".png")
#
# img = normalize(data['Y'][i], 0, 100, clip=True)
# plt.imshow(np.squeeze(img))
# plt.savefig("Y/img" + str(i) + ".png")
# plt.show()
# To show patch pairs X / Y
fig=plt.figure(figsize=(8, 4))
plt.axis('off')
h = 2
w = 5
import random
for i in range(1, w + 1):
nb = random.randrange(0, len(data['X']))
plt.subplot(h, w, i)
img = np.squeeze(normalize(data['X'][nb], 0, 100, clip=True))
plt.axis('off')
plt.imshow(img)
plt.subplot(h, w, w + i)
img = np.squeeze(normalize(data['Y'][nb], 0, 100, clip=True))
plt.axis('off')
plt.imshow(img)
plt.suptitle('5 example patches (top row: source, bottom row: target)', fontsize='small');
plt.show()