Click here to Skip to main content
13,297,547 members (46,601 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 11 May 2009

Face Collage

, 11 May 2009
Rate this:
Please Sign up or sign in to vote.
Java code to create your own face collage


This Java code can generate a collage consisting of hundreds of images, that, when viewed wholly, would look like another image.


I was exploring Picasa 3's collage options. The options were limited just to Picture Pile, Mosaic, Grid collage, etc. I was looking for an option that would make a collage forming an image. Surprisingly, I could not find out a tool on the Internet. So, I wrote a small Java program that would create a photo of photos. People who want to create a collage using their photos, to form an image of their face or another photo, can use this program. A sample of images are given below to understand how it would look.

Original Image


Collage - Zoom View shows hundreds of small images

Using the Code

For those who want to generate a few collages like this, a few tips:

  1. At the start of the program, you will find the CUSTOMIZATION PART. There are six parameters defined in this part. Modify these to best fit your requirements. More details regarding parameters are below.
  2. mainImagePath is the location where you can keep your model image.
  3. sourceFilesPath is the folder where you keep large number of images which would form the collage. More the number of source images you have, better is the clarity of collage.
  4. CollageFilePath is the folder where you want the collage to be placed.
  5. enlargeSize - I used this parameter because if the collage is of the same resolution as the original photo, the resolution of small images will be very less and hence you would not recognize the small images even when zoomed. So, enlargeSize is the number of times the collage is bigger than the model image. E.g.: If your model image is of 1600*1200 and you give enlargeSize as 3, then collage will be of 4800*3600 size.
  6. XpixelsPerBlock, YpixelsPerBlock are the number of pixels per each small block of the collage. Could be like 16, 12 or 12, 9 etc. Better to keep in 4:3 ratio as most of the images are in the same ratio. Smaller this pixel size, better the clarity of the collage image but the resolution of small images decreases and vice versa.
  7. Compile the Java code using Java 1.4 or higher version and execute it.
  8. Place the model image, source images in correct folders and create a folder to place collage too.
// ######## CUSTOMIZATION PART ######## - start

// Main image that is formed by collage of images. Must be a bitmap.
private static String mainImagePath = "C:/Image/MainImage.jpg";

// Folder that contains bitmaps which form the collage
private static String sourceFilesPath = "C:/Image/Source/";

// Location where result image to be created.
private static String CollageFilePath = "C:/Image/Collage/";

// The number of times, final collage image to be bigger than actual image, 
// so that the small images are clear when zoomed
private static int enlargeSize = 4;

// Number of pixels in each small block of the actual image. 
// Smaller the pixels, better the final collage. 
// Higher the pixels, small images in final collage look clear. 
// Better to keep the same x-y ratio(4:3 generally) as your source images.
private static int XpixelsPerBlock = 12;
private static int YpixelsPerBlock = 9;

// ######## CUSTOMIZATION PART ######## - end

Points of Interest

For techies who want to know more about the code:

  1. Read the model image. For every small block (as per XpixelsPerBlock, YpixelsPerBlock), find the average RGB components.
  2. Read all the source images and find out the average RGB components for each image. (not each block here)
  3. For each block in the model image, compare its RGB with each source images RGB (I used root of sum of squares of differences for R G and B) and find out which source image's components have minimum deviation from the block's components. Store this match in the array.
  4. Now you construct the collage. Use each block's matching source image.


  • 11th May, 2009: Initial version

Please leave a comment or mail me if you have suggestions.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
India India
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionThe java file does not run Pin
Member 1036205426-Oct-13 8:52
memberMember 1036205426-Oct-13 8:52 
QuestionNo output Pin
Member 855191011-Aug-12 22:55
memberMember 855191011-Aug-12 22:55 
QuestionHELP SIR PLEASE i Really need your Help sir... please dont ignore Pin
Ankur Gugar27-May-12 11:56
memberAnkur Gugar27-May-12 11:56 
Questionvery interesting Pin
toSKan15-May-12 4:42
membertoSKan15-May-12 4:42 
GeneralCollage without repeating images Pin
ckannan9023-Jun-10 1:57
memberckannan9023-Jun-10 1:57 
GeneralRe: Collage without repeating images Pin
abcbalaji23-Jun-10 2:36
memberabcbalaji23-Jun-10 2:36 
GeneralRe: Collage without repeating images Pin
ckannan9023-Jun-10 2:53
memberckannan9023-Jun-10 2:53 
QuestionLess function? Just make a collage, ignoring the goal image? Pin
Matt Jenner16-May-10 10:53
memberMatt Jenner16-May-10 10:53 
AnswerRe: Less function? Just make a collage, ignoring the goal image? Pin
abcbalaji16-May-10 21:24
memberabcbalaji16-May-10 21:24 
GeneralMy vote of 1 Pin
ankit8910210-May-10 0:34
memberankit8910210-May-10 0:34 
GeneralRe: My vote of 1 Pin
abcbalaji16-May-10 21:25
memberabcbalaji16-May-10 21:25 
GeneralRe: My vote of 1 Pin
abcbalaji16-May-10 21:26
memberabcbalaji16-May-10 21:26 
GeneralWonderful Pin
scolen21-Feb-10 15:13
memberscolen21-Feb-10 15:13 
GeneralRe: Wonderful Pin
Gregory Truong22-Mar-10 13:40
memberGregory Truong22-Mar-10 13:40 
GeneralPlease Help. Pin
Gregory Truong14-Feb-10 16:57
memberGregory Truong14-Feb-10 16:57 
Question???? Pin
hopefresh16-Dec-09 20:05
memberhopefresh16-Dec-09 20:05 
Generalhelp! Pin
hopefresh16-Dec-09 19:43
memberhopefresh16-Dec-09 19:43 
GeneralRe: help! Pin
abcbalaji16-Dec-09 20:07
memberabcbalaji16-Dec-09 20:07 
Questionjava.lang.OutOfMemoryError Pin
Member 19742641-Oct-09 8:27
memberMember 19742641-Oct-09 8:27 
AnswerRe: java.lang.OutOfMemoryError Pin
abcbalaji1-Oct-09 22:17
memberabcbalaji1-Oct-09 22:17 
Questionplz ansr Pin
amandeep25s2-Sep-09 0:49
memberamandeep25s2-Sep-09 0:49 
Generalrespected sir Pin
amandeep25s1-Sep-09 6:24
memberamandeep25s1-Sep-09 6:24 
Generalwhere is the main method Pin
phateey8-Jun-09 6:47
memberphateey8-Jun-09 6:47 
GeneralRe: where is the main method Pin
abcbalaji8-Jun-09 17:41
memberabcbalaji8-Jun-09 17:41 
GeneralPatented... Pin
Drew Stainton11-May-09 13:59
memberDrew Stainton11-May-09 13:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 11 May 2009
Article Copyright 2009 by abcbalaji
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid