diff --git a/README.md b/README.md index 854a8e2..40c5ac8 100644 --- a/README.md +++ b/README.md @@ -39,4 +39,6 @@ python cli.py --source --destination --rejects - Sort images according to size - Remove black or blank images - Remove white/gray images +- Remove blurry images - Use multithreading to increase performance +- Remove images with no meter readings diff --git a/cli.py b/cli.py index 18af5cf..28c7a1e 100644 --- a/cli.py +++ b/cli.py @@ -5,6 +5,11 @@ from sorter.image_sorter import process_image # CLI argument parsing def parse_arguments(): + """Parse command-line arguments. + + Returns: + argparse.Namespace: Parsed command-line arguments. + """ parser = argparse.ArgumentParser(description="Clean images from electricity meter readings.") parser.add_argument("--source", type=str, help="Path to the input folder containing the images") parser.add_argument("--destination", type=str, help="Path to the pass folder for images that pass the test") @@ -12,6 +17,8 @@ def parse_arguments(): return parser.parse_args() def main(): + """Main entry point of the program.""" + # Parse command-line arguments args = parse_arguments() diff --git a/sorter/image_sorter.py b/sorter/image_sorter.py index d9e0d01..c114a68 100644 --- a/sorter/image_sorter.py +++ b/sorter/image_sorter.py @@ -11,15 +11,17 @@ threshold_type = cv2.THRESH_BINARY def is_image_below_threshold(image_path, size_threshold): - """If the image size is below the threshold, regardless of the thresholding - result, the image will be moved to the reject folder. + """Check if the image size is below the threshold. + + If the image size is below the threshold, regardless of the thresholding result, + the image will be moved to the reject folder. Args: - image_path (_type_): _description_ - size_threshold (_type_): _description_ + image_path (str): Path to the image file. + size_threshold (int): Size threshold in bytes. Returns: - _type_: _description_ + bool: True if the image size is below the threshold, False otherwise. """ image_path = Path(image_path) size = image_path.stat().st_size @@ -27,20 +29,20 @@ def is_image_below_threshold(image_path, size_threshold): def process_image(image_path,pass_folder,reject_folder,size_threshold=75*1024): - """_summary_ + """Process an image by applying thresholding and moving it to the appropriate folder. Args: - image_path (_type_): _description_ - pass_folder (_type_): _description_ - reject_folder (_type_): _description_ - size_threshold (_type_, optional): _description_. Defaults to 75*1024. + image_path (str): Path to the image file. + pass_folder (str): Path to the pass folder for images that pass the test. + reject_folder (str): Path to the reject folder for images that fail the test. + size_threshold (int, optional): Size threshold in bytes. Defaults to 75*1024. """ image_path = Path(image_path) filename = image_path.name image = cv2.imread(str(image_path)) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - # threshold(src, dst, threshold value, max value, threshold type) + # Apply thresholding (src, dst, threshold value, max value, threshold type) _, threshold = cv2.threshold(gray, threshold_value, max_value, threshold_type) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29