-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreference_array.py
44 lines (35 loc) · 1.09 KB
/
reference_array.py
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
"""
Compute a reference image from the training set
"""
import json
import numpy as np
from PIL import Image
from pathlib import Path
from tqdm import tqdm
from parameters import PARAMETERS
# -1- Load training images
with open("datasets.json","r") as f:
datasets = json.load(f)
list_train = datasets["train"]
KMER = PARAMETERS["KMER"]
print("All images: ", len(list_train))
# -2- Load each image at a time and save the minimum value of pixels
path_img = list_train[0]
# Start with one array
npy = np.load(path_img)
# average image
ref_array = np.asarray(npy)
# minimum image
min_array = np.asarray(npy)
# load other images and sum values
for path_npy in tqdm(list_train[1:], desc="Computing avg image"):#, total=len(list_train)):
npy = np.load(path_npy)
array = np.asarray(npy)
# compute element-wise minimum between the new array and the current min_array
ref_array = np.add(array, ref_array)
min_array = np.minimum(array, min_array)
# compute avereage of arrays
ref_array = ref_array/len(list_train)
# save min_array
np.save("ref_array", ref_array)
np.save("min_array", min_array)