3

So what I would like to achieve is this:

  1. User submits Image 1 - this image is then broken down into X by X sized blocks
  2. User submits Image 2 - then the program/algorithm takes all the blocks generated in the above step, and reconstructs Image 2 using them

Example Image 2:

enter image description here

Example Output:

enter image description here

What I would like to know is, are there any libraries, or some easy way of doing this (ideally in Javascript, as I don't know any other languages) - or even some standalone software tool to accomplish this?

Joel Damien
  • 131
  • 3
  • Is image 2 somehow broken? Or are you in fact trying to figure out disparity to then operate on the second image somehow. Like making colors uniform or something. – joojaa May 12 '17 at 14:59
  • @joojaa, no, sorry for not being clearer. Image 2 is a perfect image/photo. What the aim of the algorithm is, is to take blocks of a totally different image (Image 1) - say for example comic book scans, and use that to re-draw image 2, purely for the artistic effect. – Joel Damien May 12 '17 at 15:14
  • Added example images to clarify. – Joel Damien May 12 '17 at 15:16
  • Not sure how much help this would be, but what you are after is, in effect, a version of Vector Quantisation, i.e. VQ, except that the representative vectors aren't derived/synthesised from the source image but supplied separately. You thus don't have to do the training process. – Simon F May 12 '17 at 16:17
  • 2
    ...Or you could just grab Mosaic program (maybe from http://www.brighthub.com/multimedia/photography/articles/34691.aspx ). The only tedious part would be manufacturing a set of images to corresponding to your blocks. – Simon F May 12 '17 at 16:21
  • 1
    For the case X=1 you might want to take a look here: https://codegolf.stackexchange.com/questions/33172/american-gothic-in-the-palette-of-mona-lisa-rearrange-the-pixels/33206#33206

    One solution you could think of is reducing each X by X square to one colour (e.g. by averaging) and then using the algorithm presented in the linked challenge.

    – flawr May 18 '17 at 22:09

1 Answers1

1

I would have done it with a script and NETPBM like so:

1) reducing Image1 (the tiles) to size X by X -> Image1R

2) recording the mapping from pixel values of Image1R to coordinates (no need to worry about duplicates as an exact RGB match of two or more averaged pixels is unlikely)

3) remapping Image2 using Image1R as the color map -> Image2M

4) reading pixels of Image2M, consulting the map, and picking the tile corresponding to the coordinates

5) concatenating the selected tiles across and down

There is a separate tool for all the above image manipulations in NETPBM.

Any scripting language that allows spawning other processes and supports associative arrays, would do.

Leo B.
  • 141
  • 5