图像数据维度属性统计
前言
通常,在训练神经网络模型时,需要输入固定尺寸的图像;即使对于可以输入不同尺寸图像的网络,原始图像的维度属性,对于如何将图像转换为特定尺寸输入网络也有一定的指导作用。对原始数据的尺寸分布的了解,有助于后期网络输入的确定
主要为以下2个层面的统计:
一、图像尺寸分布散点图
代码如下:
import os
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
path = '/home/VDI/sibetit-l06/research/endoscopy/data/WLI/'
heights = []
widths = []
a = []
for i in os.listdir(path):
g_truth = Image.open(os.path.join(path + i))
groundTruth = np.asarray(g_truth) # (height,width,channel)
height, width, channel = groundTruth.shape
heights.append(height)
widths.append(width)
plt.title("scatter diagram")
plt.xlabel("height")
plt.ylabel("width")
plt.plot(heights,widths,'ro')
plt.show()
结果示例:
二、相同尺寸图像的数量统计
代码如下(示例):
import os
import numpy as np
from PIL import Image
from collections import Counter
path = '/home/VDI/sibetit-l06/research/endoscopy/data/WLI/'
size = []
for i in os.listdir(path):
g_truth = Image.open(os.path.join(path + i))
groundTruth = np.asarray(g_truth) # (height,width,channel)
height, width, channel = groundTruth.shape
size.append((height, width))
result = Counter(size)
print(result)
结果示例:
Counter({(576, 768): 126, (576, 720): 49, (1080, 1920): 23, (480, 720): 21, (480, 640): 9, (533, 697): 6})