manoj-bhaskaran / My-Scripts

0 stars 0 forks source link

Optimize ```crop_colours.py``` script for faster processing #32

Closed manoj-bhaskaran closed 1 day ago

manoj-bhaskaran commented 1 day ago

The crop_colours.py script is currently experiencing slow processing times when cropping black and white blocks from images. This issue needs to be investigated and addressed to improve the performance of the script.

Areas to investigate:

  1. Pixel-by-pixel iteration: The script currently checks every pixel in an image, which is time-consuming. Investigate vectorization techniques, such as using NumPy or OpenCV, to process images more efficiently.
  2. Image processing libraries: Explore potential optimizations or alternatives to the PIL (Pillow) library, which may include using OpenCV or NumPy for faster image manipulation..
  3. Parallel processing: Consider using multi-threading or parallel processing (e.g., concurrent.futures or multiprocessing) to handle multiple images simultaneously, which could significantly speed up batch processing..
  4. Thresholding optimization: Investigate if the threshold logic for determining black and white pixels can be optimized further to minimize redundant checks across large sections of the image.
  5. Memory management: Review how memory is being handled during image processing and whether there are any opportunities to optimize memory usage, such as processing images in chunks instead of loading them entirely into memory.

Acceptance Criteria:

  1. The script should process images faster without losing the correctness of the cropping logic.
  2. If a solution is found and implemented, performance improvements should be measurable (e.g., processing time reduced for large batches of images).
  3. The script should continue to save cropped images in the "Cropped Images" folder as per the existing functionality.