We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Image Mosaic
Page Index Toggle Pages: 1
Image Mosaic (Read 901 times)
Image Mosaic
Feb 7th, 2009, 5:53am
 
As i have never worked with images before i thought i give it a try and make some image Mosaic creator... Just brightness, not in color this time...

What i came up with until now is, filling the sketch with tiles and taking the brightness out of the source image and recreate it with recangles...
Now I have to bring these two things together...
Actually i think i know what i have to do right now, but i just dont know how.
i guess i have to read through all my images at first and get the average brightness and save it somehow so that i can easily choose the right image corresponding to the "gray" value, i use right now to fill the rect.

How would i do that, and doesnt it take very longt? Im planning to use about 2500 tiles... Wouldnt it be better to precalculate the brightness rename the images like : no1_value256.gif and so one?

Just dont know how to go on at this point. Would be thankful for some hints and help.

You can download it with some tiles here:

http://www.dec32.de/public/mosaic.zip

And here is the Source
--------------------------------------------

Cube[] cube = new Cube[100000];

int tileCount = 6; //tiles in data folder

PImage[] tile = new PImage[tileCount];
float[] tileValue= new float[tileCount];


PImage seed;

int colCount;
int rowCount;
int cubeCount = 0;

void setup(){
 size( 500, 500 );
 frameRate( 24 );
 smooth();
 background(255);
 noLoop();
 noStroke();

 seed = loadImage("20x20.gif"); // image to resemble


   colCount=  seed.width;
 rowCount= seed.height;

 //loading tiles
 for ( int i = 0; i< tile.length; i++ ){
   tile[i] = loadImage( i + ".gif" );  
 }


 for(int i = 0; i < rowCount;i++){
   for(int j = 0; j < colCount;j++){

     cube[cubeCount] = new Cube(i*width/colCount,j*width/rowCount,width/colCount,height/rowCount,brightness
(seed.get(int(i),int(j))));
     cubeCount+=1;
   }
 }

}  

void draw(){
 background(255);
 for(int i = 0; i< rowCount*colCount; i++){
   cube[i].display();
 }
}

class Cube{
 float x;
 float y;
 float w;
 float h;

 float gray;


 Cube(float _x, float _y, float _h, float _w, float _gray)  {
   x = _x;
   y = _y;
   w = _w;
   h = _h;
   gray = _gray;

 }

 void display()  {

   //just for testing
   fill(gray,100);
   rect(x,y,w,h);


  // image(tile[int(random(tileCount))],x,y,w,h);

 }
}








Re: Image Mosaic
Reply #1 - Feb 7th, 2009, 12:01pm
 
Quote:
i guess i have to read through all my images at first and get the average brightness and save it somehow so that i can easily choose the right image corresponding to the "gray" value, i use right now to fill the rect.

Looks like the right approach. You need a sketch to pre-process the images, and of course the main sketch to use the data.

Quote:
How would i do that, and doesnt it take very longt?

Look at Java's File class and its listFiles() method.
The length of the operation isn't important if you do it only once.

Quote:
Im planning to use about 2500 tiles

If using only brightness, you need only 256, I think, unless you want to vary the images for a given brightness (which makes sense, after all).

Quote:
rename the images

I would just generate a text file (with tab-separated brightness and file name) to read at start of the final sketch. Perhaps make an array of 256 ArrayList from this data, the lists holding the names of the images of the given brightness.

Hope this can push you in the right direction.
Re: Image Mosaic
Reply #2 - Feb 8th, 2009, 8:10am
 
Thanks again Philho, that really helped me. I knew i had to do it in 2 steps somehow and save the results... saving it in a text file is the right approach...
Page Index Toggle Pages: 1