Another glitch-art project, still images, and moving too

I had a thought, what if you take an image and divide it in small squares and index those squares. Then take another image and chunk that up aswell. Then try to find the chunk that looks most like the current chunk from the old image, and paint that chunk from the source image to the destination. Sounds complicated? it’s not, pretend you’re making a mosaic with pieces of an other mosaic. The images are chunks are compared as black and white 16 grayscale versions of themselves. If you know mpeg encoding this is sort of like that, but naive and badly done.
So I made a program that does that, just to silence my curiosity.
Here we have two source images:
.    
And this is what they look like remade by each other:
Press them to se them in their full glory.
Of course you can change parameters such as size of the chunks, the input image, how long to look before finding a chunk that looks similar enough.
Then what if you substitue the second image for a movie, making a movie from just one image. Then what if you feed the movie with a frame from itself, how would that work? I made a small movie here where first the testshot is uneffected, then different sources and feeding itself also.

Apart from that, there are a lot of weird things you could use this for. What if you feed one movie into another. How would that look. Who would own copyright? Could you juxtapose things together? Things that are opposites? What if you applied regular glitch techniques on one of these images? For you dear reader, I publish the source code so you can use it and explore further into the depths of whatever this is.
source after the break:
 
import processing.video.*;

PImage img;

PImage oldImage; //the original that we take the chunks from
PImage newImage; //our new image that we want to remake with chunks from oldImage
PImage tmp; //tmp image that I write stuff to

int CHUNK = 8; //size of the chunks
int SPEEDSTEPPER = CHUNK*100; //in case we are lazy and do not want to wait
float frameplace =0.0;

Movie myMovie;
MovieMaker mm;

boolean fast = false;

float fps = 29.0;

HashData[] myHashData;// = new HashData[0];

int currenthashPos=0;

public void initOriginal(String filename)
{
  currenthashPos=0;
  img = loadImage(filename);
  oldImage = loadImage(filename);
  img.filter(GRAY);

  myHashData = new HashData[(img.width)*(img.height)];
  for (int i = 0; i < ((img.width)*(img.height)); i++)
  {
    // Using the short version of the constructor
    myHashData[i] = new HashData();
  }

  for (int x = 0; x < (img.width)-CHUNK; x++)  
    for (int y = 0; y < (img.height)-CHUNK; y++) 
      haschImage(x, y);
}

public void initOriginal(PImage imageIN)
{

  currenthashPos=0;
  //img = imageIN;
  //oldImage = imageIN.copy;
  img.copy(imageIN, 0, 0, width, height, 0, 0, width, height) ;
  oldImage.copy(imageIN, 0, 0, width, height, 0, 0, width, height) ;

  //img.filter(GRAY);

  myHashData = new HashData[(img.width)*(img.height)];
  for (int i = 0; i < ((img.width)*(img.height)); i++)
  {
    // Using the short version of the constructor
    myHashData[i] = new HashData();
  }

  for (int x = 0; x < (img.width)-CHUNK; x++)  
    for (int y = 0; y < (img.height)-CHUNK; y++) 
      haschImage(x, y);
}

public void setup() {
  size(640, 480, P2D);
  tmp= new PImage(width, height);
  String filename =  day()+hour()+minute()+"_c"+int(CHUNK)+"_s"+int(SPEEDSTEPPER)+".mov";
  mm = new MovieMaker(this, width, height, filename);
  println(filename);
  //  initOriginal("test1.png");
  initOriginal("flair-test2.png");

  myMovie = new Movie(this, "solid.mov");
  myMovie.pause();
}

public void convertOneMovie(PImage imgInLALA)
{

  PImage tempimg = new PImage(640, 480);
  tempimg.copy(imgInLALA, 0, 0, width, height, 0, 0, width, height) ;

  //--------------------
  // convert in image
  tempimg.filter(GRAY);

  tempimg.loadPixels();
  oldImage.loadPixels();
  int oldCurrent = (CHUNK*CHUNK);
  int currentFOUND=0;
  boolean found = false;

  for (int x = 0; xcurrenthashPos)
          break; // I made a calculus error, let's just go with the last found

        int current = tmphash.compare(myHashData[i]) ;

        if (current == 0)
        {

          tmp.copy(oldImage, myHashData[i].posX, myHashData[i].posY, CHUNK, CHUNK, tmphash.posX, tmphash.posY, CHUNK, CHUNK)  ;

          tmp.updatePixels();
          found = true;
          break;
        }
        else if (current < oldCurrent)
        {
          oldCurrent = current;
          currentFOUND = i;
          if (current < 10) //crap, let's go, it's probably good enough
            break;
        }
      }
      if (found == false)
      {

        tmp.copy(oldImage, myHashData[currentFOUND].posX, myHashData[currentFOUND].posY, CHUNK, CHUNK, tmphash.posX, tmphash.posY, CHUNK, CHUNK)  ;
      }
      // image(tmp, 0, 0);
      // mm.addFrame();
    }

    // image(tmp, 0, 0);
    // mm.addFrame();
  }
}

public HashData haschSection(PImage inImage, int startx, int starty)
{
  HashData toReturn = new HashData();
  int cnt=0;
  toReturn.posX=startx;
  toReturn.posY=starty;

  inImage.loadPixels();
  for (int x = 0; x < CHUNK; x++) {
    for (int y = 0; y < CHUNK; y++) {
      int loc = (x+startx) + (y+starty) * width;
      toReturn.numbers[cnt] = byte(map(int(red(inImage.pixels[loc])), 0, 255, 0, 16));  
      cnt++;
    }
  }
  inImage.updatePixels();
  return toReturn;
}

public void haschImage( int startx, int starty)
{

  myHashData[currenthashPos].posX=startx;
  myHashData[currenthashPos].posY=starty;

  int cnt=0;
  img.loadPixels();
  for (int x = 0; x < CHUNK; x++) {
    // Loop through every pixel row
    for (int y = 0; y < CHUNK; y++) {       int loc = (x+startx) + (y+starty) * img.width;       myHashData[currenthashPos].numbers[cnt] = byte(map(int(red(img.pixels[loc])), 0, 255, 0, 16));         cnt++;     }   }   img.updatePixels();   currenthashPos++; } void draw() {   background(0);   // only when feeding itself initOriginal(myMovie);   frameplace+=1.0/fps;   myMovie.stop();   myMovie.jump(frameplace);   myMovie.read();   //   myMovie.pause();   // convertOne("newginal.png");   convertOneMovie(myMovie);   image(tmp, 0, 0);   mm.addFrame();   // saveFrame(day()+hour()+minute()+second()+"-####.png");   println("MADE ONE FRAME :"+frameplace+"/"+myMovie.duration());   //noLoop();   if (frameplace >myMovie.duration())
  {
    noLoop();
    mm.finish();
    println("the end");
  }
}

void keyPressed() {
  if (key == ' ') {
    // Finish the movie if space bar is pressed
    mm.finish();
    // Quit running the sketch once the file is written
    exit();
  }
}

class HashData // By tradition, class names start with an initial uppercase letter
{
  int posX;
  int posY; // Position
  byte[] numbers = new byte[(CHUNK*CHUNK)]; 
  HashData()
  {
    //println("created");
  }
  int compare(HashData cmp)
  {
    int toreturn = (CHUNK*CHUNK);
    //println("toreturn "+toreturn);

    for (int i =0;i

2 thoughts on “Another glitch-art project, still images, and moving too

  1. This is AMAZING!!!

    I would love to play with this, but unfortunately I am getting errors (while running it through Processing):

    line 98:

    int current = tmphash.compare(myHashData[i]) ;


    Cannot find anything named “tmphash”

    —-
    I attempted every solution I could think of, but cannot figure this one out…

    I already replaced the “<“s with “<"s that must have created themselves when you pasted the code to your blog…also, the end seems to be cut off, but I haven't been able to get to that point to problem solve…

    I would really like to get this going so I can begin experimenting with it. I have spent the past few hours trying to debug the code, but to no avail….yet…

    thank you much…

    ps…BRILLIANT work btw!!

Leave a Reply