Skip to content

Commit

Permalink
added code for printing the process of processing
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpcshangbo committed Mar 20, 2024
1 parent 5469a3b commit 5be3cef
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions DirectoryImageMaskProcessor_1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from PIL import Image
import numpy as np
import os


Expand All @@ -17,10 +16,19 @@ def process_directory(self):
os.makedirs(self.red_output_directory, exist_ok=True)
os.makedirs(self.green_output_directory, exist_ok=True)

# Process each image in the input directory
for image_file in os.listdir(self.input_directory):
if image_file.lower().endswith(("png", "jpg", "jpeg")):
self.process_image(image_file)
image_files = [
f
for f in os.listdir(self.input_directory)
if f.lower().endswith(("png", "jpg", "jpeg"))
]
total_images = len(image_files)
print(f"Found {total_images} images to process.")

for idx, image_file in enumerate(image_files, start=1):
print(f"Processing image {idx}/{total_images}: {image_file}")
self.process_image(image_file)

print("All images processed successfully.")

def process_image(self, image_file):
# Load and convert the image
Expand Down Expand Up @@ -55,17 +63,16 @@ def create_and_save_mask(self, channel, image_file, output_directory, mask_type)

# Save the mask
mask.save(mask_path)
print(f"Saved {mask_type} mask: {mask_path}")


# Example usage
if __name__ == "__main__":
input_directory = (
"images_folder" # This directory should contain the images to process.
)
input_directory = "images_folder" # Adjust this path to your folder of images

processor = DirectoryImageMaskProcessor(input_directory)
processor.process_directory()

print(
f"Processing complete. Check the parent directory of '{input_directory}' for the results."
f"Processing complete. Check the parent directory of '{input_directory}' for the 'red_crack_masks' and 'green_spall_masks' folders."
)

0 comments on commit 5be3cef

Please sign in to comment.