Skip to main content

Image Processing Pipeline

Premium

You're asked to finish an image processing pipeline. The project includes sample images, a partial harness, and a pipeline spec that lists transformations in order. Your program needs to apply each transformation to every image and write the results to an output directory.

You don't need prior image processing experience. Pillow is already installed, so part of the exercise is learning an unfamiliar API quickly.

Starter code and solution
Python 3.11+ (Pillow)
Download code

What's in the codebase

  • ops.py. The operation registry and the individual op functions. This is where you work.
  • pipeline.py. Spec loading, apply_pipeline, and main(), which reads fixtures/ and writes output/.
  • fixtures/pipeline.txt. The pipeline spec.
  • fixtures/. Sample images, plus a generator script that recreates them.
  • tests/test_image_pipeline.py. Optional self-check tests.

The spec is one operation per line: an op name followed by whitespace-separated arguments. Blank lines and # comments are ignored, and steps apply top to bottom.

grayscale rotate 90 crop 0 0 64 64 resize 32 32 convert JPEG

Your task

Load every image in fixtures/ and apply the spec's steps in order, writing each result to output/. load_spec() already parses the spec into Step objects and apply_pipeline() folds them over an image, so your job is to make the operations they name actually run.

grayscale is implemented as a worked example of the shape each op takes. Implement the rest: invert, rotate, crop, resize, and convert.

What to focus on

The algorithm is straightforward. The challenge is working through gaps in the specification while learning an unfamiliar library.

  • Research under time pressure. You will need to look things up. Time-box that work and keep the implementation moving.
  • Extensibility. Adding a new operation later should mean registering one function, not editing a loop.
  • Reading the spec carefully. Several of the operations are ambiguous in ways the spec doesn't resolve. Finding those and raising them is the exercise.

Questions worth asking

At least two operations in the specification are underspecified, and one behaves differently from the other pixel transformations. Read the full specification before you start, then raise the ambiguities instead of choosing silently.

Also decide out loud what should happen when the spec names an operation you don't recognize, and what should happen when one image in the batch fails. Silently swallowing either is a poor answer, but so is letting one bad file kill the whole run without comment.

Using AI on this problem

This is a natural fit for research-level AI use because the Pillow API is worth looking up rather than memorizing. Check any generated snippet against the documentation or a quick run before you trust it, and explain how you verified it.

Leveling signals

Mid-levelGets the plumbing and most operations working. Needs nudges toward the clarifying questions, and tests when reminded.
SeniorUses the registry cleanly, raises the ambiguous operations unprompted, adds a new operation without touching the loop, and validates looked-up API details as they go.
Staff+All of the above, plus framing: proposes error isolation and per-image pipelines before being asked, articulates the extensibility contract, and doesn't over-engineer for scale that isn't there.