Giter Site home page Giter Site logo

nnakul / ft-visualisation Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 1.03 MB

The project uses Discrete Fourier Transform to express a drawing as a sequence of epicycles characterised by their initial phase, radius and frequency.

License: GNU General Public License v3.0

CSS 0.03% JavaScript 99.84% HTML 0.07% Python 0.06%
fourier-transform discrete-fourier-transform visualisation gallery

ft-visualisation's Introduction

ABOUT

The project uses the discrete Fourier transform (DFT) algorithm to build an application that replicates whatever is drawn by representing it as a series of epicycles. In other words, the application aims at obtaining the fourier series representation of the drawing, in a similar way in which it is obtained for a sqaure or a triangular wave. The DFT converts a finite sequence of equally-spaced samples of a function into a same-length sequence of equally-spaced samples of the discrete-time Fourier transform (DTFT), which is a complex-valued function of frequency. Each complex-valued term in this sequence can be interpreted as an epicycle which has certain specific characteristics -- radius, frequency of the phasor and initial phase. For simplicity, the terms in the sequence are ordered by decreasing magnitude. The center of the epicycle corresponding to the first term is chosen strategically to fit the drawing on the black-board. The center of every epicycle depends on the current phase of the previous epicycle. The trajectory of the circumferential point on the last epicycle where it intersects its phasor, creates the drawing.

NOTE : INDEX.html is the main page of the site

PAGE O1 - REPLICATING A DRAWING

On the main page, the user can draw anything. The algorithm computes its discrete Fourier transform and then shows the visualisation to verify how the generated sequence actually represents that drawing. The original number of epicycles (which is also the maximum number of epicycles possible) depends on the number of discrete points in the drawing. The precision and sharpness of the mimicked drawing depends on the number of epicycles the user wants to use. This number can be customised using the scroller below the drawing board.

PAGE O2 - VISUALIZING DFT ON A PICTURE FROM GALLERY

The main page links to the second page where the user can select any of the available pictures from the gallery. It is interesting to see how the algorithm can represent any drawing by a sequence of sinusoids/epicycles, pretty much like how the Fourier series is calculated for any simple function. Note that the points on the silhouette of these available drawings were not determined manually but a procedure was followed to convert any picture into an ordered sequence of points that when joined one after the other, form that very picture.

  1. Pick any image from the internet. It is strongly advised to select simple line drawings without any filled shapes/components.
  2. Drop the image in the ONLINE STENCIL MAKER to turn it into a black-n-white design/stencil. Adjusting the edges and the sharpness/darkness of the picture, cleans any random or isolated strokes/blots in it that might lead to some stray lines in the replicated drawing. This step is however redundant if the image selected in the first place is a perfect line drawing but anyway, it was observed that passing the image through this stencil-maker significantly improves the results obtained in the final step.
  3. Keep the stencil's picture in the same directory/folder as the FIND_CONTOUR.py file. Put the name of the picture in its code and execute it. The contour-points will be written in a text document in JSON notation. Copy the entire content and assign it intact to a javascript variable and add this new .js file to the LINE_DRAWINGS folder. Besides, the new javascript file will have to be tethered to the second html page and a button will have to be designed to command the drawing of Fourier replica of the picture.
FIND_CONTOUR.py basically solves the Travelling Salesman problem in a naiive greedy approach. Firstly, the pixels in the image are scanned in row-major fashion and the coordinates of the black-colored pixels are pushed in the list. This jumbled sequence of points is ordered by choosing any starting point and finding the nearest unvisited point. This process is continued iteratively until all the points are visited. Note that the contour-points obtained by this method might give some or quite a few stray lines in its replicated version; but still the picture finally created is recognizable and very similar to the picture selected in the first step of the procedure.

    

ft-visualisation's People

Contributors

nnakul avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.