JMosaic - A Java Based PhotoMosaic Generator



About JMosaic


JMosaic is a program that allows users to encode an image with new meanings that may or may not have been intended by the original author. The program works by allowing a user to easily generate a photomosaic (a picture that is made up of smaller pictures, usually with some connection to the main image) without having any previous knowledge of image manipulation. JMosaic works by prompting the user to choose an image from their hard drive, as well as a destination for the final result. The user can then select several parameters that affect the final appearance of the image. Both the size of the mosaic tiles and the number of images that will be used to produce the final photomosaic. The final step is to enter a search term into the text field. This search term will be used to search the internet for new images that will later be used to produce the photomosaic.


By enabling the user to enter a search term that will be used to generate the photomosaic JMosaic enables the user to encode the resulting image with a new meaning. This new meaning can go along with the content of the original image, such as this mosaic made by searching for "War" with a source image of soldiers fighting in Iraq:

or the result can be ironic, such as this mosaic of a bomber created with the search term "Bush:"

Either tactic allows for a user encode virtually any image with a new meaning.



How JMosaic Works


JMosaic is a program written using Java 1.4.2. The program uses the basic java SDK for most of its functions, with google searches being performed by using the Google API that is provided freely from Google. Once a user has selected an image to use as a source as well as a tile size for the mosaic, the number of images to search for and the search term the program begins its work. First the program takes the source image and generates a two dimensional array of pixels. Each pixel represents the average color of a block of the image whose width and height are the size specified by the user during the setup. After this has been done the program begins to search Google for images that match the search term provided by the user. The googleAPI returns web pages that match the criteria set forward by the user and these web pages are then parsed for images. JMosaic looks for any image whose aspect ratio is at least 5:2 or 2:5 and whose width and height are at least 150 pixels. This is done to try and minimize the number of garbage or interface images that are grabbed by the parser. Once the desired number of images has been reached the program begins to fit these found images into the source image. For every pixel in the two dimensional array of pixels created from the original image JMosaic searches through the found images for any whose highest color saturation is within some distance of the highest saturation of the source pixel. Of the images that match this initial critera JMosaic chooses the image whose average color is closest to the average color of the original pixel. This is the source code for this search:

private MosaicPiece getBestFit(ArrayList subset, int redValue, int greenValue, int blueValue){
		MosaicPiece bestFit = (MosaicPiece) subset.get(0);
		Color tempColor = new Color(bestFit.getAverageColor());
		int tRed = tempColor.getRed();
		int tGreen = tempColor.getGreen();
		int tBlue = tempColor.getBlue();
		int currentDistance = getAverageDistance(redValue, greenValue, blueValue,
				tRed, tGreen, tBlue);
		for(int i = 0; i < subset.size(); i++){
			MosaicPiece temp = (MosaicPiece) subset.get(i);
			tempColor = new Color(temp.getAverageColor());
			tRed = tempColor.getRed();
			tGreen = tempColor.getGreen();
			tBlue = tempColor.getBlue();
			int averageDistance = getAverageDistance(redValue, greenValue, blueValue,
					tRed, tGreen, tBlue);
			if(averageDistance < currentDistance){
				bestFit = temp;
				currentDistance = averageDistance;
			}
		}
	return bestFit;
}

Once this search has been completed the correct found images are then written into the proper location in the final image, producing a found photomosaic.


JMosaic can be downloaded Here

Back