File size: 1,015 Bytes
19e3743 7ec09e6 19e3743 7ec09e6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import os
import glob
from PIL import Image
def convert_high_bit_depth_images(root_dir, threshold_bit_depth):
print(f"Searching for images in {root_dir} and its subdirectories...")
for filepath in glob.iglob(os.path.join(root_dir, '**/*.(jpg|jpeg|png)'), recursive=True):
print(f"Found image: {filepath}")
with Image.open(filepath) as img:
bit_depth = img.bits
print(f"Image bit depth: {bit_depth} bits")
if bit_depth > threshold_bit_depth:
print(f"Converting image to 16-bit: {filepath}")
img = img.convert('I;16')
img.save(filepath)
print(f"Conversion complete: {filepath}")
else:
print(f"Image bit depth is already 16-bit or lower: {filepath}")
print("Conversion complete!")
def main():
root_dir = 'E:\\training_dir'
threshold_bit_depth = 16
convert_high_bit_depth_images(root_dir, threshold_bit_depth)
if __name__ == "__main__":
main()
|