-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResizeing.py
More file actions
34 lines (32 loc) · 1.17 KB
/
Resizeing.py
File metadata and controls
34 lines (32 loc) · 1.17 KB
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
29
30
31
32
33
34
print("Started")
import os
from PIL import Image
print('Library Imported')
def resize_and_convert_to_grayscale(image_path, size=(250, 250)):
try:
# Open an image file
with Image.open(image_path) as img:
# Resize the image
img = img.resize(size)
# Convert the image to grayscale
gray_img = img.convert('L')
# Save the grayscale image
gray_img.save(image_path)
print(f"Image {image_path} has been resized and converted to grayscale.")
except IOError:
print(f"Unable to open image {image_path}. Skipping.")
def process_images_in_folder(folder_path):
for filename in os.listdir(folder_path):
if filename:
image_path = os.path.join(folder_path, filename)
resize_and_convert_to_grayscale(image_path)
# Replace 'path_to_your_folder' with the path to the folder containing your images
print("Begining Process")
process_images_in_folder('Pistol')
print("Done")
process_images_in_folder('Knife')
print("Done")
process_images_in_folder('eval_pistol')
print("Done")
process_images_in_folder('eval_Knife')
print("Done")