ParametricPress / 01-unraveling-the-jpeg

Source code for Unraveling the JPEG
https://parametric.press/issue-01/unraveling-the-jpeg/
MIT License
245 stars 21 forks source link

Lerp the DCT coefficients of two images #15

Open OmarShehata opened 3 years ago

OmarShehata commented 3 years ago

Inspired by this tweet: https://twitter.com/JobvdZwan/status/1400477315738574856

What happens if you lerp between the Fourier representations of two drawings?

What happens if you do that at the 8x8 group level of two JPGs just before the final steps of decompressing them and turning them back into an image?

I think it would be cool to put together a standalone demo that lets you pick two images and have a slider to go back and forth.

I put together a little experiment exploring this idea, that replaces the coefficients of one image with another, one by one, starting with the highest frequency, over time:

https://user-images.githubusercontent.com/1711126/120941941-8a9f9980-c6f3-11eb-920c-8d6e665c73c3.mp4

It's not fast enough to be realtime, but I think that's only because the article is doing a lot of work every time the coefficients change, and maybe that can be optimized a bit.

OmarShehata commented 3 years ago

Just to note this down here, the above demo was created entirely in the browser console. Here's a gist with the code: https://gist.github.com/OmarShehata/895e42474c5604439888426cb57dab75

  1. First I copied the coefficients from the "Full Discrete Cosine Transform" editor, of the default cat image
  2. Then I opened the article with this URL which opens it using the fox image.
  3. Then I defined catData in the fox article:
var catData = `COPY_PASTE_ALL_THE_CAT_COEFFICIENTS`;// from the cat article
  1. Then I clear the console so it's not so slow
  2. Then I selected the editor with the browser inspector (specifically <div class="ace-editor ace_editor ace-monokai ace_dark">) such that $0 referred to this element
  3. Then I pasted in the code from the gist, which will start to swap the coefficients, 100 numbers per frame
OmarShehata commented 3 years ago

Other notes for building a standalone prototype that does this lerp:

https://github.com/ParametricPress/01-unraveling-the-jpeg/blob/b655460c84cb1fd3fe781740f13fe961425c6fbc/components/utils/ImageUtilities.js#L363-L376

https://github.com/ParametricPress/01-unraveling-the-jpeg/blob/b655460c84cb1fd3fe781740f13fe961425c6fbc/components/utils/ImageUtilities.js#L378-L405

OmarShehata commented 3 years ago

And of course it'd be really cool to be able to drag and drop any 2 images to morph them like that