Overview

This Processing (Java) application takes an input image, extracts its contours using OpenCV, and reconstructs the outline using rotating circles (epicycles) driven by the Discrete Fourier Transform (DFT).
The pipeline converts the image to grayscale, applies thresholding, and extracts contour points. The x and y coordinates of those points are separated and each fed independently into a DFT, producing a set of frequency coefficients that are interpreted as rotating circles with specific amplitudes, frequencies, and phases.
Two chains of epicycles — one for x and one for y — rotate simultaneously. The tip of each chain traces the respective coordinate, and their intersection reconstructs the original contour as time sweeps from to .
How It Works
Contour Extraction
The input image (e.g. a silhouette of a cat) is loaded and processed through an OpenCV pipeline: conversion to grayscale, binary thresholding, and contour detection via findContours. The largest contour is selected and its points are sampled at regular intervals to produce an ordered list of coordinate pairs.
These sampled points define the discrete signal that will be decomposed by the DFT. Separating x and y into independent arrays allows each dimension to be transformed and drawn with its own set of epicycles.
Discrete Fourier Transform
The DFT is applied independently to the x-coordinate array and the y-coordinate array. For each frequency index , the transform computes real and imaginary components by correlating the signal with sine and cosine basis functions:
Each coefficient is converted to polar form — amplitude , phase , and frequency — defining a rotating circle. The coefficients are sorted by descending amplitude so the largest circles are drawn first, giving rapid visual convergence.
Epicycle Drawing
Two independent chains of epicycles are rendered on screen — one arranged horizontally (producing the x-coordinate) and one vertically (producing the y-coordinate). Each chain stacks rotating circles end-to-end: the centre of circle sits on the rim of circle .
As time advances from to , the tip of the x-chain and the tip of the y-chain each trace a coordinate value. A horizontal line from the y-chain tip and a vertical line from the x-chain tip intersect at the drawn point, progressively reconstructing the full contour on the canvas.
The Mathematics
DFT Formulation
The Discrete Fourier Transform converts a finite sequence of equally-spaced samples into a same-length sequence of complex frequency coefficients:
Each coefficient encodes a circle with amplitude , frequency , and phase . The original signal is reconstructed by summing these rotating phasors:
Sorting the coefficients by descending amplitude means the first few circles capture the coarse shape while later, smaller circles add finer detail — analogous to how low-frequency Fourier components carry most of the signal energy.
Technology Stack
Tools & Libraries
- Processing (Java) — Creative-coding framework used for real-time rendering and animation
- OpenCV (gab.opencv) — Image processing: grayscale conversion, thresholding, contour extraction
- PeasyCam — 3D camera control for interactive scene navigation
- Discrete Fourier Transform — Custom implementation converting contour coordinates into frequency coefficients
- Real-time Animation — Epicycle chains drawn each frame, progressively tracing the reconstructed contour