10 types of datasets
|
@ -15,7 +15,7 @@ def calculate_clarity_score(image_path,target_size=(512, 512)):
|
||||||
return cv2.Laplacian(image, cv2.CV_64F).var()
|
return cv2.Laplacian(image, cv2.CV_64F).var()
|
||||||
|
|
||||||
|
|
||||||
def process_images(input_folder, output_folder,clarity_score_threshold):
|
def process_images(input_folder, output_folder,clarity_score_low,clarity_score_high):
|
||||||
if not os.path.exists(input_folder):
|
if not os.path.exists(input_folder):
|
||||||
print(f"输入文件夹不存在:{input_folder}")
|
print(f"输入文件夹不存在:{input_folder}")
|
||||||
return
|
return
|
||||||
|
@ -28,11 +28,11 @@ def process_images(input_folder, output_folder,clarity_score_threshold):
|
||||||
continue
|
continue
|
||||||
file_path = os.path.join(root, filename)
|
file_path = os.path.join(root, filename)
|
||||||
# print(f'file_path is {file_path}')
|
# print(f'file_path is {file_path}')
|
||||||
i+=1
|
|
||||||
try:
|
try:
|
||||||
# 清晰度检测
|
# 清晰度检测
|
||||||
clarity_score = calculate_clarity_score(file_path)
|
clarity_score = calculate_clarity_score(file_path)
|
||||||
if clarity_score > clarity_score_threshold:
|
if clarity_score > clarity_score_low and clarity_score<clarity_score_high:
|
||||||
|
i+=1
|
||||||
# 读取图片
|
# 读取图片
|
||||||
with Image.open(file_path) as img:
|
with Image.open(file_path) as img:
|
||||||
# resize
|
# resize
|
||||||
|
@ -46,17 +46,19 @@ def process_images(input_folder, output_folder,clarity_score_threshold):
|
||||||
os.makedirs(output_subfolder)
|
os.makedirs(output_subfolder)
|
||||||
output_path = os.path.join(output_subfolder, os.path.splitext(filename)[0] + ".png")
|
output_path = os.path.join(output_subfolder, os.path.splitext(filename)[0] + ".png")
|
||||||
img.save(output_path, format="PNG")
|
img.save(output_path, format="PNG")
|
||||||
print(f"处理并保存图片{i}:{file_path} -> {output_path}")
|
print(f"处理并保存图片{i}:{file_path} -> {output_path}********")
|
||||||
else:
|
else:
|
||||||
print(f"********图片 {file_path} 清晰度评分 {clarity_score} 不满足要求,跳过********")
|
print(f"********图片 {file_path} 清晰度评分 {clarity_score} 不满足要求,跳过")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"********处理图片 {file_path} 时出错:{e}********")
|
print(f"********处理图片 {file_path} 时出错:{e}")
|
||||||
|
print(f'——————处理完毕,成功/图片数量: {i}/{len(files)}——————\n')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
input_folder = 'data_process/datasets/source' # 输入文件夹路径
|
input_folder = 'data_process/datasets/temp' # 输入文件夹路径
|
||||||
output_folder = 'data_process/datasets/target' # 输出文件夹路径
|
output_folder = 'data_process/datasets/target' # 输出文件夹路径
|
||||||
clarity_score_threshold =50
|
clarity_score_low = 50
|
||||||
process_images(input_folder, output_folder,clarity_score_threshold)
|
clarity_score_high =3000
|
||||||
|
process_images(input_folder, output_folder,clarity_score_low,clarity_score_high)
|
||||||
|
|
||||||
|
|
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 107 KiB |
After Width: | Height: | Size: 106 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 380 KiB |
After Width: | Height: | Size: 129 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 280 KiB |
After Width: | Height: | Size: 162 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 135 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 301 KiB |
After Width: | Height: | Size: 240 KiB |
After Width: | Height: | Size: 319 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 151 KiB |
After Width: | Height: | Size: 257 KiB |
After Width: | Height: | Size: 200 KiB |
After Width: | Height: | Size: 196 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 127 KiB |
After Width: | Height: | Size: 56 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 196 KiB |
After Width: | Height: | Size: 192 KiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 162 KiB |
After Width: | Height: | Size: 107 KiB |
After Width: | Height: | Size: 67 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 111 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 179 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 135 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 280 KiB |
After Width: | Height: | Size: 994 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 131 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 1.0 MiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 815 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.0 MiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 180 KiB |
After Width: | Height: | Size: 722 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 67 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 186 KiB |
After Width: | Height: | Size: 444 KiB |
After Width: | Height: | Size: 171 KiB |
After Width: | Height: | Size: 205 KiB |
After Width: | Height: | Size: 143 KiB |
After Width: | Height: | Size: 340 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 306 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 252 KiB |
After Width: | Height: | Size: 305 KiB |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 284 KiB |
After Width: | Height: | Size: 262 KiB |
After Width: | Height: | Size: 160 KiB |
After Width: | Height: | Size: 208 KiB |
After Width: | Height: | Size: 322 KiB |
After Width: | Height: | Size: 372 KiB |