Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

UniquePixels

Repaints any image so that every pixel is a different color — no shade is ever used twice — while keeping the picture recognizable.

Hokusai's Great Wave off Kanagawa on the left; on the right the same print rebuilt so that no two pixels share a color — the flat sky blooms into a pink, gold and cyan rainbow while the wave stays razor-sharp

Left: Hokusai's Great Wave.  Right: the same image, repainted so that every one of its ~21,800 pixels is a different color.

UniquePixels is a Java/Swing desktop app that reconstructs a source image from a palette of distinct colors, giving each pixel a color that appears exactly once. It samples a large candidate palette across the RGB cube, stores it in a 3-D k-d tree, and for every pixel pulls the nearest still-unused color — then deletes that color so it can never appear again. The effect is strongest over large smooth areas: a plain sky has nowhere to hide, so it spreads across the whole spectrum into rainbow noise while edges stay sharp.

Gallery

Van Gogh's The Starry Night rebuilt from unique colors: the swirls read perfectly while the dark foreground picks up rainbow speckle A synthetic vaporwave sunset whose smooth sky gradient becomes banded rainbow noise, sun and mountains intact

A hot-air balloon over a pale sky; the sky blooms into rainbow static while the balloon stays crisp Da Vinci's Mona Lisa rebuilt from unique colors; the sfumato background dithers into greens and magentas while the face stays coherent

Features

  • Every pixel unique. Candidate colors are sampled across the RGB cube and each is used at most once — placing a color removes it from the palette.
  • Fast nearest-color search via a 3-D k-d tree over RGB space, periodically pruned and rebalanced as colors are consumed.
  • Six fill orders — left, right, up, down, and inward / outward spirals — that change how the reconstruction grows.
  • Four color-target modes — exact single pixel, 3×3 source average, 5×5 output average, and random 5×5 sampling.
  • Adjustable accuracy (0.25×–5×), trading palette size (match quality) against speed.
  • Live side-by-side preview with a running completion percentage; the finished picture is written to image.png.

Run it

Requires a JDK (the project targets Java 8, and also builds and runs on current JDKs) and a desktop environment for the Swing UI.

cd Painting
javac -d bin $(find src -name '*.java')
java -cp bin main.Program

Then Pick image to load a source (max area ~255³ pixels), choose a direction, comparison mode, and accuracy, and click Run. The result is written to image.png in the working directory. (Painting/ is also an Eclipse project you can import directly.)

How it works

The candidate palette is a uniform grid sampled through the RGB cube — sized to cover every pixel, scaled by the accuracy setting — and inserted into a 3-D k-d tree. Pixels are visited in the chosen order; for each one the app computes a target color (the source pixel, or a neighborhood average), asks the tree for the nearest color still available, paints it, and deletes it so it cannot recur. Every ~2,500 placements the tree is pruned and rebalanced so lookups stay fast as the palette shrinks.

The fill order shapes the result

The same smiley reconstructed three ways: the original, a linear left-to-right column sweep, and an outward spiral; the linear version bands the background horizontally while the spiral makes a radial vignette

The same smiley, filled two of six ways — a linear column sweep (center) vs. an outward spiral (right). Because colors run out as you go, the visiting order decides where the leftover hues pool: horizontal bands vs. a radial vignette.


Tech: Java (Swing/AWT). The bundled kdtree package is adapted from the Java Machine Learning Library (Simon Levy / Thomas Abeel), GPLv2.

Showcase inputs: Hokusai's The Great Wave off Kanagawa, da Vinci's Mona Lisa, and van Gogh's The Starry Night are public domain; the hot-air-balloon photo is public domain (David E. Lucas / DPLA); the sunset and smiley are drawn by the program itself.

About

Repaints an image so every pixel is a unique color, using a k-d tree for nearest-color matching

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages