这里写目录标题
- 1.批量裁剪指定大小的数据图片集
- 2.获取图像灰度直方图信息
-
- 3.
1.批量裁剪指定大小的数据图片集
from PIL import Image
import os.path
rootdir = r'F:\scientific research'
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
print('parent is :' + parent)
print('filename is :' + filename)
currentPath = os.path.join(parent, filename)
print('the fulll name of the file is :' + currentPath)
img = Image.open(currentPath)
print(img.format, img.size, img.mode)
box1 = (856, 529, 1316, 989)
image1 = img.crop(box1)
image1.save(r"F:\scientific research\result10.28_1" + '\\' + filename)
2.获取图像灰度直方图信息
2.1 单张image
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('DSC_3681.JPG')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
hist, bins = np.histogram(gray.ravel(), 256, [0, 256])
plt.hist(gray.ravel(), 256, [0, 256])
plt.xlabel('Pixel value')
plt.ylabel('Pixel count')
plt.title('Grayscale Histogram')
plt.show()
2.2 批量获取
3.