Tile image on specific location without space between them [duplicate]

Possible Duplicate:
How to combine images with the same dimensions in a grid?

I would like to arrange images without any space between their edges as each piece is made to connect with others.

The images should not necessarily be merged but simply tiled.

My ultimate purpose is to use a Manipulate to generate different arrangements.

So, how can I place those images in a coordinate system so I can define 9 positions and assign those locations to the images without any space between them ?

Below my attempt using Grid and 2 example of the desired Output once I figure this out. Those composition were generated using Java Scripts.

EDIT :

The problem with Grid or ImageAssemble is they would not allow for "empty slots", which is an option I would like to have as shown in the last image for example.

-
Do the results you want differ in any way from this question? –  rcollyer Jan 26 '12 at 14:13
@rcollyer, I am having trouble to express it, but what I need is to be able to assign positions from 1 to 9 as I will implement some rules about the "neighborhood". I would group the elements by their attributes : Color or B&White for example and say for example that no B&W should be close to a color one. So i am looking for the best system that will enable me that. I am happy to merge or delete if you think they are redundant. –  500 Jan 26 '12 at 14:46
So what you need is code to organize the images, not necessarily merge them together, correct? –  rcollyer Jan 26 '12 at 14:47
@rcollyer, Yes. The underlying subject is I tried to create sets of elements that can be re arranged in many way. I want to use mathematica to generate and select a lot of combination. While now they are all tiled together I might want to have empty locations at some point. –  500 Jan 26 '12 at 14:52
@rcollyer, maybe this will help laeh500.com/LAEH/Meet_Arto.html –  500 Jan 26 '12 at 14:53
show 2 more comments

marked as duplicate by rcollyer, Ｊ. Ｍ.♦, Mr.Wizard♦, Szabolcs, rm -rf♦Jan 26 '12 at 15:41

One can in fact use the (once documented) third argument of Rectangle[] to tile images. Here's an example I cooked up:

imgs = {ExampleData[{"TestImage", "Clock"}],
ExampleData[{"TestImage", "Elaine"}],
ExampleData[{"TestImage", "JellyBeans"}],
ExampleData[{"TestImage", "Lena"}],
ExampleData[{"TestImage", "Mandrill"}],
ExampleData[{"TestImage", "Peppers"}],
ExampleData[{"TestImage", "Splash"}],
ExampleData[{"TestImage", "Tiffany"}],
ExampleData[{"TestImage", "U2"}]};

mat = Partition[RandomSample[Range[9]], 3];
Graphics[Table[Rectangle[{j, k}, {j + 1, k + 1}, imgs[[mat[[j + 1, k + 1]]]]],
{j, 0, 2}, {k, 0, 2}]]


The idea is that, you have nine images to distribute on a 3×3 grid; you thus partition some permutation of the numbers $1$ to $9$ in groups of three (that is, mat), have the indices of Table[] map to a corresponding entry of mat, and then that entry of mat has a corresponding index in the list imgs. The extension to any number of images to be arranged in a grid should be straightforward.

-
Does this allow for empty slots in the array? –  rcollyer Jan 26 '12 at 15:32
Just use a conditional as needed: If[j == 2 && k == 1, (* then *) {White, Rectangle[{j, k}, {j + 1, k + 1}]}, (* else *) Rectangle[{j, k}, {j + 1, k + 1}, imgs[[mat[[j + 1, k + 1]]]]]] –  Ｊ. Ｍ. Jan 26 '12 at 15:39
@J.M., Thank you very much ! –  500 Jan 26 '12 at 15:45

If your images are the same size, a quick and dirty hack is using ImageAssemble in place of Grid. (I used that before several times.)

You can generate "empty slots" for use with ImageAssemble like this: Rasterize[Graphics[{}, ImageSize -> ImageDimensions[existingImage]], "Image"]. Adjust the required image size as needed.

Otherwise the Grid option to use should be Spacings, but I always have some trouble with that:

Regarding importing images, you can consider building on the following simpler code:

ImageResize[#, 256] & /@ Import /@ FileNames["B*.png"]

-
beat me to it by 2 seconds –  Heike Jan 26 '12 at 14:11
@Heike There's still the question of doing this properly (no gaps) with Grid though ... –  Szabolcs Jan 26 '12 at 14:17
Setting Spacings->{0,0} works on my system. –  Heike Jan 26 '12 at 14:19
@Szabolcs, Thank You ! Could you explain me the use of "*" in the importing function ? –  500 Jan 26 '12 at 14:47
@500 FileNames["B*.png"] will give you all files start with a B and end in .png in the current directory. The keyword to google for is wildcard. –  Szabolcs Jan 26 '12 at 14:49
show 2 more comments

For what it's worth, when working at magnification 200% I get no gaps in Grid using Spacing -> {0, 0}. You could therefore Rasterize and ImageResize from there as needed.

-
Wizard, thank you ! –  500 Jan 26 '12 at 15:04