python常用图像处理操作总结
创始人
2024-05-26 01:56:55
0

这里写目录标题

  • 1.批量裁剪指定大小的数据图片集
  • 2.获取图像灰度直方图信息
    • 2.1 单张image
    • 2.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)# img.show()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.

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...