File size: 844 Bytes
96ed3dd |
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 |
import pandas as pd
import numpy as np
import cv2
import statistics
from tqdm import tqdm
from glob import glob
def calculate_normalization_parameters(path=None):
# data = pd.read_csv(path_to_train_csv)
data = glob('NIH/images/*.png')
mean = 0
std = 0
height = []
width = []
for i in tqdm(data):
image = cv2.imread(i)[:, :, ::-1]
h, w, _ = image.shape
image = image.reshape(-1, 3)
mean += np.mean(image, axis=0)
std += np.std(image, axis=0)
height.append(h)
width.append(w)
mean = mean / (255 * len(data))
std = std / (255 * len(data))
print("median height:", statistics.median(height))
print("median width:", statistics.median(width))
print("mean:", mean)
print("std:", std)
return mean, std
calculate_normalization_parameters() |