Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📸 Universal Image Filter (CS50 Python Remake)

An optimization-driven remake of CS50's Filter (Harder) project. This application breaks free from the limitations of the original C language version by replacing custom BMP parser data structures with standard system file explorer prompts and multi-format support (PNG, JPEG, BMP, WebP), while running image kernels at lightning-fast hardware speeds using vectorized math matrices.


✨ Features

  • Multi-Format Processing: Seamlessly load and save all modern standard image types via Pillow integration instead of manual 24-bit uncompressed BMP parsing.
  • Native GUI File Picker: No more tedious terminal string typing. The script hooks directly into your operating system's native window dialog to open files and select target saving coordinates.
  • Hardware Vectorization Boost: Replaced heavy Python nested for loop logic—which takes minutes to step through millions of pixels—with pre-compiled C-speed NumPy matrix operations that run complex kernels in milliseconds.
  • Portable Automation Shell: Includes an interactive batch command menu interface you can pin straight to your desktop as a portable launch shortcut.

🛠️ The Architecture

The system is cleanly divided into two specialized standalone components:

  1. filter.py: The application driver. It reads parameter flags, invokes OS file dialog abstractions, processes the Pillow-to-NumPy coordinate conversions, and handles safety clipping metrics.
  2. helpers.py: The pure mathematics layer. Houses the structural algorithmic modifications for image modifications.

Available Pipelines

  • -g (Grayscale): Maps color channels down to exact average channel intensities.
  • -r (Reflect): Mirrors column arrays horizontally across matrix lines.
  • -b (Blur): Implements a 3x3 array box neighborhood shift average algorithm.
  • -e (Edges): Computes image structural vectors via horizontal ($G_x$) and vertical ($G_y$) Sobel kernel operators.

🚀 Setup & Installation

Prerequisites

Make sure you have Python 3 installed on your machine.

Installation

  1. Clone your repository down to your local directory:

    git clone https://github.com
    cd YOUR_REPO_NAME
  2. Install the necessary mathematical and imaging dependencies:

    pip install pillow numpy

💻 How To Run It

The Interactive Way (Easiest)

Run the automated shell file locally or via your desktop shortcut:

./Run_Filter.bat

Simply choose a flag in the command prompt menu (e.g. -e), select your image when the file picker appears, and enter a new filename when prompted.

The Terminal Way

If you prefer explicit terminal calls, pass your required algorithm flag directly to the driver script:

python filter.py -e

🧠 What I Learned (C vs. Python)

This project highlights a massive milestone in software optimization:

  • Why Python Loops Drag: Writing standard for r in range(height): lines over standard high-definition photo grids forces the Python interpreter to read operations line-by-line over millions of pixels, grinding calculations to a halt.
  • The Power of Vectorization: By mapping the calculations onto multi-dimensional array slices (np.pad, np.sqrt), the operations bypass standard runtime execution loops entirely and move directly onto pre-compiled C binaries inside the underlying hardware layout, matching C performance with just a few clean lines of code.

About

An optimized Python remake of CS50's "Filter (Harder)" project. It swaps custom C BMP struct parsing for multi-format support (PNG, JPEG, WebP) and native system file pickers. By replacing slow loops with vectorized NumPy matrices, it runs heavy Sobel edge and box blur kernels at lightning-fast, pre-compiled C hardware speeds.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages