Friday, June 27, 2008

Photo mosaic project

Following link may give you a little bit help

http://www.andreaplanet.com/andreamosaic/

It is a free software download and use


What we actually have to do to create a photo mosaic is as follows:

(1)Select
a picture first(as a background picture)

(2)shrink it down to a 31 by 31 (or suitable size)image

(3) Reduce it with only 27 color values,

(4)Enlarge the image using the nearest neighbor approach

(5)Find at least one picture whose average color is one of the 27 possible colors

that appear in the picture

(6)Shrink those images so that they are the size of the 'pixels' in the enlarged picture

(7)Calculate the average colors of the smaller images,

(8) Sort them in an array so that for each color there is one image,

(9)Replace the 'pixels' in the big image with the smaller images.

Step (1)
Picture(from Google search), saved on the disk and read with the following code.
Code in MATLAB
cd c:\users\admin\pictures
pic=imread('catmosaic.jpg');
pic=double(pic)/255;
imshow(pic)
size (pic)
ans =

124 124 3








Step2
shrink it down to a 31 by 31 image

Octave Code(I am trying to write it in MATLAB too)
octave-3.0.1.exe:1>
octave-3.0.1.exe:1> function Z=zoom2(limg,scale)
> rows=floor(size(limg,1)*scale);
> cols=floor(size(limg,2)*scale);
> for i=1:rows;
> for j=1:cols;
> a=round(i/scale);
> b=round(j/scale);
> Z(i,j,:)=limg(a,b,:);
> end;
> end;
> endfunction
octave-3.0.1.exe:2> cd c:\users\admin\pictures
octave-3.0.1.exe:3> pic=imread('catmosaic.jpg');
octave-3.0.1.exe:4> pic=double(pic)/255;
octave-3.0.1.exe:5> pic=zoom2(pic,1/4);
octave-3.0.1.exe:6> imshow(pic)
octave-3.0.1.exe:7> size(pic)
ans =

31 31 3





Step 3

Reduce it with only 27 color values.
Octave code is as follows( I will try to write in MATLAB too)

octave-3.0.1.exe:8> function B=draw27(A)
> A=double(A);
> for i=1:size(A,1)
> for j=1:size(A,2)
> for k=1:3
> B(i,j,k)=floor(A(i,j,k)/86)*86+42;
> endfor
> endfor
> endfor
> endfunction
octave-3.0.1.exe:9> cd c:\users\admin\pictures
octave-3.0.1.exe:10> pic=imread('catmosaic.jpg')
octave-3.0.1.exe:11> pic27=draw27(pic);
octave-3.0.1.exe:12> imshow(double(pic27)/255)





Step 4

Enlarge(20 times) the image using the nearest neighbor approach.
Size of the image will be 620 x 620
Octave code is like this:

cols=floor(size(simg,2)*scale);
for i=0:(rows-1);
for j=0:(cols-1);
a=floor((i/scale)+1);
b=floor((j/scale)+1);
if (a>0) & (a<=original_rows) & (b>0) & (b<=original_cols)
Z(i+1,j+1,:)=simg(a,b,:);
end;
end;
end;
endfunction
cd c:\Users\admin\pictures
A=imread("pic27.jpg");
picstep3=stretch2(A,20);
size(picstep3);
B=double(picstep3)/255;
imwrite("strechedpic.jpg",B(:,:,1),B(:,:,2),B(:,:,3))


























Step 5

Find at least one picture whose average color is one of the 27 possible colors that appear in the picture.

No comments: