Collage creator?

A forum where you can announce your awesome project(s).

Moderator: MaxCoderz Staff

Post Reply
User avatar
anykey
Extreme Poster
Posts: 420
Joined: Mon 31 Jan, 2005 3:36 am
Location: In the matrix
Contact:

Collage creator?

Post by anykey »

In compsci, we get to work on an end-of-year project, which can be pretty much anything (my automatic-porn-downloader didn't get approved :D ).
Here's my idea: create a program that creates cool photo collages from a directory of images and saves it as a gif (or whatever works best). This would have to be done in java, since that's the language we're working with in class.
The first step would be to create an array of the images (easy!) and figure out the "average" of their colors (hard!). How would I do that? I don't know much about image processing, but I'm assuming there's a fairly simple algorithm that can do that.
Once I have each image processed, I need to take the "main" image (the one I'm making the collage of), and break it into sections. Using the previous algorithm, I'd then have to find the "average" of the colors of each section.
Finally, I need to piece the sections back together and save the resulting image.
I hope at least one of you guys knows how to do something like this...
I think, therefore iMac
Image
User avatar
thegamefreak0134
Extreme Poster
Posts: 455
Joined: Mon 23 Jan, 2006 10:09 pm
Location: In front of a Computer, coding
Contact:

Post by thegamefreak0134 »

You shouldn't find the "average" color for any image (if these are going to be regular photos) but should break each photo into sections and find the average of all the sections. This will give you more data to work with. (the color of the 4 corners seems like it would be enough.)

You will need to break your original image down into its pixelated parts, possibly performing the same breaking into sections, so as to gather a good average of every "pixel" of the final image. Then compare this list with your original photos, and pick the best match for each of the pictures. You should probably have this process go from the inside to the outside, especially if the colloge will represent a face, since this will be the area that gathers the most visual attention.

If you have your photos separated by corners, then you need to separate your colloge photo into 4x4 squares of pixels. Then pick a starting point and find the difference between the selected grid and your calculated average pixel color for every image in your collection. (This process could take a while if you have a lot of pictures.) Place the best (or first exact, if you encounter one) picture into this slot, mark it off the list so it wont be used again, and proceed on with the list.

The hardest part of this particular project it seems will be determining the "average" color ov every region of the photos. To do this, it seems like you would separate the red, green, and blue regions out of all the pixels in an area, average these regions together, and there is your average color. (Not sure if this will work by simply averaging the whole color, but it does not seem like it would.)

Good luck with the project, and anyone else who can please post comments, as I get this feeling there are more ways to do something like this.

-gamefreak
I'm not mad, just a little crazy.

DarkNova - a little side project I run.
User avatar
elfprince13
Sir Posts-A-Lot
Posts: 234
Joined: Sun 11 Dec, 2005 2:21 am
Contact:

Post by elfprince13 »

here's how a lot of robotic vision programs do it: scan the middle 20 or so lines of each column, and take the average of that.
User avatar
anykey
Extreme Poster
Posts: 420
Joined: Mon 31 Jan, 2005 3:36 am
Location: In the matrix
Contact:

Post by anykey »

Scanning the middle 20 lines of each column sounds like it would give more accurate results...I guess it really depends on the picture.
I'm going to ask my dad about this, since he used to work with image processing. Hopefully this project will take off and actually go somewhere!
I think, therefore iMac
Image
User avatar
anykey
Extreme Poster
Posts: 420
Joined: Mon 31 Jan, 2005 3:36 am
Location: In the matrix
Contact:

Post by anykey »

Okay, it turns out to find the average rgb value, you can just average the R, G, and B numbers (who would've thought!).
As for the overall project, my dad warned me that it was probably a little over my head for now. I might work on some bits and pieces of it still.
I think, therefore iMac
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

In case it's any use, the way to detect closest colours is to use Pythagoras' thereom (so distance = sqrt((r1-r2)²+(g1-g2)²+(b1-b2)²)). You don't need to take the square root when comparing distances, though.
Last edited by benryves on Wed 20 Dec, 2006 6:05 pm, edited 1 time in total.
User avatar
anykey
Extreme Poster
Posts: 420
Joined: Mon 31 Jan, 2005 3:36 am
Location: In the matrix
Contact:

Post by anykey »

wait...I'm confused...
What exactly does it do?
I think, therefore iMac
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I was going under the assumption that you'd need to match closest colours (to match tiles to source pixels), and to get the difference between colours (for sorting purposes) you can use Pythagoras.
User avatar
anykey
Extreme Poster
Posts: 420
Joined: Mon 31 Jan, 2005 3:36 am
Location: In the matrix
Contact:

Post by anykey »

maybe...
if it clears up any uncertainty, "mosaic" is more apt to what I'm doing than "collage".
I think, therefore iMac
Image
Post Reply