Skip to content

hunterchen7/WaveFormer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Converts lines from an image into parametric equations using Fourier transforms.

Usage: pretty rudimentary at the moment, just change "img" input in main.rs to desired image and run it like a normal rust program. generated equations will appear in images/equations.txt. see generated islands in images/lines.png.

Basic premise of how it works:

  • Step 1: Convert image into edges using an edge detection algorithm. For now, it just uses a basic Sobel filter modified with a threshold, but I'm currently working on implementing the Canny edge detection algorithm.
  • Step 2: Get lines from images using a DFS that keeps track of the path and explores all 8 neighbouring pixels.
  • Step 3: Construct equations of all the lines using Fourier transformations, omitting lines containing < n points. (currently n = 16)
    • Computes as follows:
      1. coefficients $cx_k = \sum_{i=0}^{N-1} \cos (\frac{2\pi k i}{N}) p_{x,i} + \sin(\frac{2\pi k i}{N}) p_{y,i}$ and $cy_k = \sum_{i=0}^{N-1} \cos(\frac{2\pi k i}{N}) p_{y,i} - \sin(\frac{2\pi k i}{N}) p_{x,i}$

      2. then we have $x(t) = \sum_{k=-\text{freqs}}^{\text{freqs}} \frac{cx_k}{N} \cos(k\pi t) - \frac{cy_k}{N} \sin(k\pi t)$ and $y(t) = \sum_{k=-\text{freqs}}^{\text{freqs}} \frac{cx_k}{N} \cos(k\pi t) + \frac{cy_k}{N} \sin(k\pi t)$

Example usage:

Description Input image Edges Generated lines/paths Graphed equations
simple example with 1 pixel wide lines, without edge detection (lines2.png) image n/a image image
slightly more complex example, with Sobel filter applied (shapes1.png) image image image much more of a mess! image
Let's see it attempt the Toronto skyline (toronto.png) image image image Surprisingly lucid, although Desmos was barely keeping it together image

About

Convert images into parametric equations using Fourier transforms and edge detection algorithms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages