snorpey / triangulation

image triangulation experiment
http://snorpey.github.io/triangulation/
MIT License
487 stars 87 forks source link

Background on the Code #4

Closed RoyiAvital closed 9 years ago

RoyiAvital commented 9 years ago

Could you explain how do you create this effect?

Namely:

  1. Blur.
  2. Find Edges.
  3. Etc...

Thank You.

snorpey commented 9 years ago

The actual triangulation of the image starts in the process.js in a function called processImage.

An overview what happens in there:

  1. The image is put on two separate canvas elements. The image data on the first canvas is used for calculating the shape of the polygons. Several filters are applied to this canvas throughout the process. The image data on the second canvas is never changed and used for calculating the color of the polygons later.
  2. The image data is blurred, using Superfast Blur by @quasimondo . This blurring library may not be quite as accurate as others (Though I haven't compared it to other libraries extensively, so I might be wrong), but it is very fast, which I think is more important here.
  3. A greyscale filter is applied to the image data
  4. Edges are detected
  5. Edge point coordinates are calculated from the edges image data
  6. From all edge point coordinates, a random number is selected
  7. The point coordinates are fed into @ironwallaby's delaunay.js library, which calculates polygons based on those coordinates.
  8. It calculates the center coordinate of each polygon and looks up the color for this coordinate in the original image (the second canvas from step 1)
  9. it draws the polygons on the screen

Let me know if this helps or if you want me to clarify anything. :-)

snorpey commented 9 years ago

closing this issue, please leave a comment if you have further questions.

RoyiAvital commented 9 years ago

Hi, This is great.

Could you link the parameters from the Online Demo to the steps you mentioned?

Thank You.

snorpey commented 9 years ago

@RoyiAvital i'm not completely sure i understand the question... which parameters are you referring to?