first commit

This commit is contained in:
pmn 2025-05-11 17:23:03 +08:00
commit 09bae36854
21 changed files with 63 additions and 0 deletions

BIN
datasets/source/2/001.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 KiB

BIN
datasets/source/2/002.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

BIN
datasets/source/2/003.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
datasets/source/2/004.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
datasets/source/2/005.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
datasets/source/2/006.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

BIN
datasets/source/2/007.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 KiB

BIN
datasets/source/2/008.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
datasets/source/2/009.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
datasets/source/2/010.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
datasets/target/2/001.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 KiB

BIN
datasets/target/2/002.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

BIN
datasets/target/2/003.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

BIN
datasets/target/2/004.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB

BIN
datasets/target/2/005.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

BIN
datasets/target/2/006.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 KiB

BIN
datasets/target/2/007.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 KiB

BIN
datasets/target/2/008.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

BIN
datasets/target/2/009.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

BIN
datasets/target/2/010.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 KiB

63
image_qualified.py Normal file
View File

@ -0,0 +1,63 @@
import cv2
from PIL import Image
import numpy as np
import os
def calculate_clarity_score(image_path):
"""
计算图片的清晰度评分
"""
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
if image is None:
raise ValueError(f"无法读取图片:{image_path}")
return cv2.Laplacian(image, cv2.CV_64F).var()
def process_images(input_folder, output_folder,clarity_score_threshold):
if not os.path.exists(input_folder):
print(f"输入文件夹不存在:{input_folder}")
return
for root, dirs, files in os.walk(input_folder):
print(f'——————正在处理文件夹:{root}, 图片数量:{len(files)}——————')
i = 0
for filename in files:
if not filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif', '.jfif')):
continue
file_path = os.path.join(root, filename)
# print(f'file_path is {file_path}')
i+=1
try:
# 清晰度检测
clarity_score = calculate_clarity_score(file_path)
if clarity_score > clarity_score_threshold:
# 读取图片
with Image.open(file_path) as img:
# resize
img = img.resize((512, 512))
# output_subfolder
relative_path = os.path.relpath(root, input_folder)
output_subfolder = os.path.join(output_folder, relative_path)
# print(f'root: {root}, input_folder: {input_folder}, relative_path: {relative_path}, output_subfolder: {output_subfolder}')
if not os.path.exists(output_subfolder):
os.makedirs(output_subfolder)
output_path = os.path.join(output_subfolder, os.path.splitext(filename)[0] + ".png")
img.save(output_path, format="PNG")
print(f"处理并保存图片{i}:{file_path} -> {output_path}")
else:
print(f"********图片 {file_path} 清晰度评分 {clarity_score} 不满足要求,跳过********")
except Exception as e:
print(f"********处理图片 {file_path} 时出错:{e}********")
if __name__ == "__main__":
input_folder = 'PMN_WS/data_process/datasets/source' # 输入文件夹路径
output_folder = 'PMN_WS/data_process/datasets/target' # 输出文件夹路径
clarity_score_threshold =50
process_images(input_folder, output_folder,clarity_score_threshold)