I used the 27 images below to get the mosaic. Actually since I did not really color match the pictures, I could have used any reasonable number, if my array had 1000 different pictures or 10 different pictures, it would still find the closest average color to the pixel being replaced. The important thing would be to pick enought pictures with different colors.
To shrink the images to a certain n by n size I used
function [ smim ] = shrinknm( picture,n, m)
fy = double(n)/double(size(picture,1));
fx = double(m)/double(size(picture,2));
Mp = floor(size(picture,1)*fy);
Np = floor(size(picture,2)*fx);
smim(:,:,1)=zeros(Mp,Np);
smim(:,:,2)=zeros(Mp,Np);
smim(:,:,3)=zeros(Mp,Np);
for i = 0:(Mp-1)
for j = 0:(Np -1)
for x = floor(i/fy):ceil((i+1)/fy)-1
for y = floor(j/fx):ceil((j+1)/fx)-1
ival = picture(x+1,y+1,:);
if(x less than i/fy)
ival =ival*(1+x-i/fy);
end
if (x+1 greater than (i+1)/fy)
ival = ival*(1+((i+1)/fy)-(x+1));
end
if (y less than j/fx)
ival = ival*(1-(j/fx)+y);
end
if (y+1 > (j+1)/fx)
ival =ival*(1-(y+1)+(j+1)/fx);
end
smim(i+1,j+1,:) = smim(i+1,j+1,:)+ival;
end;
end;
smim(i+1,j+1,:) = smim(i+1,j+1,:)/(1/fx)/(1/fy);
end
end
I saved the following script for reading in pictures in a text file to be reused:
a1 = imread('a1.jpg');
a2 = imread('a2.jpg');
a3 = imread('a3.jpg');
a4 = imread('a4.jpg');
a5 = imread('a5.jpg');
a6 = imread('a6.jpg');
a7 = imread('a7.jpg');
a8 = imread('a8.jpg');
a9 = imread('a9.jpg');
a10 = imread('a10.jpg');
a11 = imread('a11.jpg');
a12 = imread('a12.jpg');
a13 = imread('a13.jpg');
a14 = imread('a14.jpg');
a15 = imread('a15.jpg');
a16 = imread('a16.jpg');
a17 = imread('a17.jpg');
a18 = imread('a18.jpg');
a19 = imread('a19.jpg');
a20 = imread('a20.jpg');
a21 = imread('a21.jpg');
a22 = imread('a22.jpg');
a23 = imread('a23.jpg');
a24 = imread('a24.jpg');
a25 = imread('a25.jpg');
a26 = imread('a26.jpg');
a27 = imread('a27.jpg');
a28 = imread('a28.jpg');
a29 = imread('a29.jpg');
a30 = imread('a30.jpg');
a31 = imread('a31.jpg');
a32 = imread('a32.jpg');
b1 = floor(shrinknm(double(a1),30,30)/86)*86+42;
b2 = floor(shrinknm(double(a2),30,30)/86)*86+42;
b3 = floor(shrinknm(double(a3),30,30)/86)*86+42;
b4 = floor(shrinknm(double(a4),30,30)/86)*86+42;
b5 = floor(shrinknm(double(a5),30,30)/86)*86+42;
b6 = floor(shrinknm(double(a6),30,30)/86)*86+42;
b7 = floor(shrinknm(double(a7),30,30)/86)*86+42;
b8 = floor(shrinknm(double(a8),30,30)/86)*86+42;
b9 = floor(shrinknm(double(a9),30,30)/86)*86+42;
b10 = floor(shrinknm(double(a10),30,30)/86)*86+42;
b11 = floor(shrinknm(double(a11),30,30)/86)*86+42;
b12 = floor(shrinknm(double(a12),30,30)/86)*86+42;
b13 = floor(shrinknm(double(a13),30,30)/86)*86+42;
b14 = floor(shrinknm(double(a14),30,30)/86)*86+42;
b15 = floor(shrinknm(double(a15),30,30)/86)*86+42;
b16 = floor(shrinknm(double(a16),30,30)/86)*86+42;
b17 = floor(shrinknm(double(a17),30,30)/86)*86+42;
b18 = floor(shrinknm(double(a18),30,30)/86)*86+42;
b19 = floor(shrinknm(double(a19),30,30)/86)*86+42;
b20 = floor(shrinknm(double(a20),30,30)/86)*86+42;
b21 = floor(shrinknm(double(a21),30,30)/86)*86+42;
b22 = floor(shrinknm(double(a22),30,30)/86)*86+42;
b23 = floor(shrinknm(double(a23),30,30)/86)*86+42;
b24 = floor(shrinknm(double(a24),30,30)/86)*86+42;
b25 = floor(shrinknm(double(a25),30,30)/86)*86+42;
b26 = floor(shrinknm(double(a26),30,30)/86)*86+42;
b27 = floor(shrinknm(double(a27),30,30)/86)*86+42;
b28 = floor(shrinknm(double(a28),30,30)/86)*86+42;
b29 = floor(shrinknm(double(a29),30,30)/86)*86+42;
b30 = floor(shrinknm(double(a30),30,30)/86)*86+42;
b31 = floor(shrinknm(double(a31),30,30)/86)*86+42;
b32 = floor(shrinknm(double(a32),30,30)/86)*86+42;
imshow(b1/255);
imshow(b2/255);
imshow(b3/255)
imshow(b4/255)
imshow(b5/255)
imshow(b6/255)
imshow(b7/255)
imshow(b8/255)
imshow(b9/255)
imshow(b10/255)
imshow(b11/255)
imshow(b12/255)
imshow(b13/255)
imshow(b14/255)
imshow(b15/255)
imshow(b16/255)
imshow(b17/255)
imshow(b18/255)
imshow(b19/255)
imshow(b20/255)
imshow(b21/255)
imshow(b22/255)
imshow(b23/255)
imshow(b24/255)
imshow(b25/255)
imshow(b26/255)
imshow(b27/255)
imshow(b28/255)
imshow(b29/255)
imshow(b30/255)
imshow(b31/255)
imshow(b32/255)
A = {b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17 b18 b19 b20 b21 b22 b23 b24 b25 b26 b27};