← all repositories
theamusing/perfectPixel

When AI pixel art forgets how to pixel

A Python utility that reverse-engineers the grid from sloppy AI-generated pixel art and snaps it back to clean, countable squares.

1.5k stars Python Other AIImage · Video · Audio
perfectPixel
Velocity · 7d
+9.8
★ / day
Trend
steady
star history

What it does

Perfect Pixel takes AI-generated “pixel style” images — the kind where Stable Diffusion or a chatbot almost got it right but the grid is warped, uneven, or just guesswork — and figures out what the actual grid size should be. It then resamples the image onto that grid so every pixel lands where it belongs. There’s a web demo, a pip-installable package with optional OpenCV, and a ComfyUI node for the diffusion crowd.

The interesting bit

The grid detection runs on FFT magnitude analysis, not brute-force search. It finds the dominant spatial frequency, generates candidate grid lines, then uses Sobel edge detection to nudge those lines onto actual image boundaries. The whole thing is a three-step pipeline (FFT → edge refinement → resample) that treats the pixel grid as a signal-processing problem rather than a graphics one.

Key highlights

  • Auto-detects grid size or lets you override manually
  • Two backends: OpenCV for speed, NumPy-only for minimal dependencies
  • Three sampling modes: center, median, or majority vote per grid cell
  • Adjustable refinement intensity to control how aggressively it hunts for edges
  • ComfyUI node available without touching the core algorithm

Caveats

  • The README is vague on accuracy limits; it works best on images that are already “almost” pixel art (recommended input size 512–1024)
  • No quantification of how non-square or irregular a grid can be before detection fails
  • The “lightweight” backend drops OpenCV but keeps the same algorithm — performance trade-offs aren’t benchmarked

Verdict

Grab this if you’re generating pixel art with AI and need clean output for physical crafts (perler beads, cross-stitch) or game assets. Skip it if your source images aren’t already grid-ish; it’s a refiner, not a magic wand.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.