mirror of
https://github.com/andwati/image-sort.git
synced 2026-10-18 00:22:51 +00:00
Added docstrings for documentation
This commit is contained in:
@@ -39,4 +39,6 @@ python cli.py --source <image folder path> --destination <pass folder> --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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
+13
-11
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user