Sunday, July 6, 2008

Photomosaic (FINAL)

















original image


















I divided my "big picture" into 40 tiles, 15x15 pixels each,and then assigned them according to the big picture's average colour(Jen's method).
I had difficulties running the program because function "increase" did not increase matris exactly to 600x600, although I checked the size of this matrix previously, and it was correct.I used the following function to check the average colour of my big picture:

function[B]= average(X)
B=sum(sum(X))/(size(X,1)*size(X,2));
end

This is the final code for my photomosaic:

A1=imread('stry night.jpg');
T1=decrease4(A1,15/124,15.67/124);
A2=imread('blue 4.jpg');
T2=decrease4(A2,15.42857/104,15/160);
A3=imread('128_214_214t3.jpg');
T3=decrease4(A3,15/115,15.64/149);
A4=imread('bluish.jpg');
T4=decrease4(A4,15.13/107,15/160);
A5=imread('214_42_128tt28.jpg');
T5=decrease4(A5,15/90,15/135);
A6=imread('czerwony1.jpg');
T6=decrease4(A6,15.13/107,15/160);
A7=imread('dark blue.jpg');
T7=decrease4(A7,15/133,15/89);
A8=imread('dark emerald.jpg');
T8=decrease4(A8,15/96,15/137);
A9=imread('42_128_42-t10.jpg');
T9=decrease4(A9,15/160,15/114);
A10=imread('-42,214,128-t11.jpg');
T10=decrease4(A10,15/132,15/99);
A11=imread('128_128_214t12.jpg');
T11=decrease4(A11,15/92,15/123);
A12=imread('128_42_214t13.jpg');
T12=decrease4(A12,15/116,15/116);
A13=imread('-42,42,214,t14.jpg');
T13=decrease4(A13,15.357/103,15/137);
A14=imread('fuisha lite.jpg');
T14=decrease4(A14,15/113,15/150);
A15=imread('128_42_128-t16.jpg');
T15=decrease4(A15,15.64/107,15/160);
A16=imread('gray.jpg');
T16=decrease4(A16,15.64/107,15/160);
A17=imread('jasna zielen.jpg');
T17=decrease4(A17,15/148,15/160);
A18=imread('42_214_214-t20.jpg');
T18=decrease4(A18,15/533,15/768);
A19=imread('onion zmienionyt21.jpg');
T19=decrease4(A19,15/603,15/640);
A20=imread('orange fish.jpg');
T20=decrease4(A20,15/475,15/605);
A21=imread('214_42_214t23.jpg');
T21=decrease4(A21,15/113,15/150);
A22=imread('purple-red.jpg');
T22=decrease4(A22,15.13/107,15/160);
A23=imread('warm green.jpg');
T23=decrease4(A23,15.85/110,15/160);
A24=imread('214_214_128t4.jpg');
T24=decrease4(A24,15/114,15/143);
A25=imread('zielen srednia.jpg');
T25=decrease4(A25,15/114,15/146);
A26=imread('128_214_128t30.jpg');
T26=decrease4(A26,15/160,15/114);
A27=imread('yellow glow.jpg');
T27=decrease4(A27,15/534,15/800);

% End of loading Images----------------


A=imread('flower.jpg');
B=decrease4(A,40/600,40/400);
B=255*B;
C=floor(B/86)* 86+42;
double(C)/255;
D=increase2v(C,15.175)
%image(D);

for i=0:39;
for j=0:39;
pixel=((average(D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)))*255);
pixel=floor(pixel/86)*86+42;
if pixel(:,:,1)==42 && pixel(:,:,2)==42&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T1;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==128&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T8;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==214&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T18;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==42&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T7;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==42&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T13;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==128&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T2;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==214&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T10;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==128&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T9;
end;
if pixel(:,:,1)==42 && pixel(:,:,2)==214&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T27;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==128&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T16;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==42&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T22;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==214&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T3;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==128&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T17;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==128&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T11;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==214&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T23;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==42&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T12;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==214&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T26;
end;
if pixel(:,:,1)==128 && pixel(:,:,2)==42&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T15;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==214&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T4;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==42&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T6;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==128&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T14;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==214&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T27;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==214&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T24;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==42&&pixel(:,:,3)==128
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T5;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==128&&pixel(:,:,3)==42
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T20;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==128&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T19;
end;
if pixel(:,:,1)==214 && pixel(:,:,2)==42&&pixel(:,:,3)==214
D((15*i+1):(15*i+15),(15*j+1):(15*j+15),:)=T21;
end;
end;
end;
image(D)

Tuesday, July 1, 2008

Photomosaic (4)

Here are my tiles to replace similar colours on "canvas".
I did not have time to look at the results of checking the average colour, so I shrunk a couple more pictures, since today my computer was not as bad as usual


















A1=imread('bllue3.jpg');
image(A1)
size(A1)
T1=decrease4(A1,15/160,15.67/107);
image(T1), axis off
A2=imread('blue 4.jpg');
T2=decrease4(A2,15.42857/104,15/160);
image(T2), axis off
A3=imread('blue 4.jpg');
T3=decrease4(A2,17/115,14.31/149);
image(T3), axis off
A4=imread('bluish.jpg');
T4=decrease4(A4,15.13/107,15/160);
B4=average(T4)
A5=imread('brown 2.jpg');
T5=decrease4(A5,15/120,15/160);
average(T5)
A6=imread('brownish.jpg');
T6=decrease4(A6,15/160,15.67/107);
A7=imread('czerwony1.jpg');
T7=decrease4(A7,15.13/107,15/160);
average(T7)
A8=imread('dark blue.jpg');
T8=decrease4(A8,15/133,15/89);
average(T8)
A9=imread('dark emerald.jpg');
T9=decrease4(A9,15/96,15/137);
average(T9)
A10=imread('dark green.jpg');
T10=decrease4(A10,15/160,15/114);
A11=imread('emerald dark.jpg');
T11=decrease4(A11,15/132,15/99);
average(T11)
A12=imread('fiolet 1.jpg');
T12=decrease4(A12,15/92,15/123);
A13=imread('fiolet.jpg');
T13=decrease4(A13,15/116,15/116);
A14=imread('fiolet3.jpg');
T14=decrease4(A14,15.357/103,15/137);
A15=imread('fuisha lite.jpg');
T15=decrease4(A15,15/113,15/150);
A16=imread('fuisha.jpg');
T16=decrease4(A16,15.64/107,15/160);
A17=imread('gray.jpg');
T17=decrease4(A17,15.64/107,15/160);
A18=imread('gray1.jpg');
T18=decrease4(A18,15.64/107,15/160);
A19=imread('jasna zielen.jpg');
T19=decrease4(A19,15/148,15/160);
A20=imread('niebieski1.jpg');
T20=decrease4(A20,15/533,15/768);
A21=imread('onion.jpg');
T21=decrease4(A21,15/603,15/640);
A22=imread('orange fish.jpg');
T22=decrease4(A22,15/475,15/605);
A23=imread('pale yellow.jpg');
T23=decrease4(A23,15/113,15/150);
A24=imread('purple-red.jpg');
T24=decrease4(A24,15.13/107,15/160);
A25=imread('warm green.jpg');
T25=decrease4(A25,15.85/110,15/160);
A26=imread('white.jpg');
T26=decrease4(A26,15/114,15/143);
A28=imread('yellow1.jpg');
T28=decrease4(A28,15/90,15/135);
A29=imread('zielen srednia.jpg');
T29=decrease4(A28,15/114,15/146);

Well, now I have to somehow put my tiles on the big picture.(?)

Monday, June 30, 2008

Photomosaic (3)

I found another picture I liked better for canvas. Here are all previous steps with my new picture:

A=imread('flower.jpg');
>> image(A);
size(A)

ans =

600 400 3

>> B=decrease4(A,20/600,20/400);
image(B)
size(B)

ans =

20 20 3

>> B=255*B;
C=floor(B/86)*86+42;
image(double(C)/255)

I tried to decrease the size of my image to 20x20, but it did not look good.
So I stayed with 40x40.


B=decrease4(A,40/600,40/400);
image(B)
size(B)

ans =

40 40 3

>> image(B)
>>
>>
>> B=255*B;
C=floor(B/86)*86+42;
image(double(C)/255)


>> D=increase2v(C,15);
>> image(D)














































Above my 27 colours.

Sunday, June 29, 2008

Photomosaic (2)

I was trying to decrease number of colours in my picture, but I was always getting either a white picture or a black picture.After trying this code

B=255*B;
C=floor(B/86)*86+42;
image(double(C)/255)
D=increase(C,30);



I received the following image.

















I am not very happy with this image.

PROJECT- PHOTOMOSAIC

STEP 1

I spent a lot of time looking for the right image.
Here it is.

A=imread('Monet11.jpg')
image(A);





















size(A)

ans =

349 350 3

I decreased the original image using average over all pixels in the destination point.

B=decrease4(A,20/349,20/350);
image(B)




















size(B)

ans =

20 20 3

Tuesday, June 24, 2008

Assignment # 8, question 4 and 5 (finished)

Question#4

If we enlarge an image beyond its original size, GIMP calculates the missing pixels by interpolation, but it does not add any new detail. The more an image is enlarged, the more blurred it becomes. The appearance of an enlarged image depends upon the interpolation method we choose.

To change the image size, either some pixels have to be removed or new pixels must be added. The process you use determines the quality of the result. The Interpolation drop down list provides a selection of available methods of interpolating the color of pixels in a scaled image:
Interpolation
• None: No interpolation is used. Pixels are simply enlarged or removed, as they are when zooming. This method is low quality, but very fast.
• Linear: This method is relatively fast, but still provides fairly good results.
• Cubic: The method that produces the best results, but also the slowest method.
Sinc (Lanczos 3): New with GIMP-2.4, this method gives less blur in important resizings.

http://docs.gimp.org/en/gimp-image-scale.html


Question # 5

>> A=imread('Start.jpg');
>> B=decrease2(A,.8);
C=decrease2(A,.6);
D=decrease2(A,.4);
E=decrease2(A,.2);
>>
>> size(A)

ans =

512 768 3

>> size(B)

ans =

409 614 3

>> size(C)

ans =

307 460 3

>> size(D)

ans =

204 307 3

>> size(D)

ans =

204 307 3

>> B=255*B;
C=255*C;
D=255*D;
E=255*E;
A(52:size(B,1)+(52-1),77:size(B,2)+(77-1),:)=B;
A(52*2:size(C,1)+(52*2-1),77*2:size(C,2)+(77*2-1),:)=C;
A(52*3:size(D,1)+(52*3-1),77*3:size(D,2)+(77*3-1),:)=D;
A(52*4:size(E,1)+(52*4-1),77*4:size(E,2)+(77*4-1),:)=E;
image(A)





Assignment 8, question # 3

Enlarge images using factor 1/f and bilinear intearpolation approximation.
We may use the same function that we used in assignment #7:

function[B]=increase3(A,f)
A=double(A)/255
p=floor(size(A,1)*f);
q=floor(size(A,2)*f);
for i=0:p-1
for j=0:q-1
c=i/f;
d=j/f;
r=floor(c);
s=floor(d);
if(r>0)&(r<256)&(s>0)&(s<256)
for k=1:3
B(i,j,k)=[1-c+r,c-r]*[A(r,s,k),A(r,s+1,k);
A(r+1,s,k),A(r+1,s+1,k)]*[1-d+s;d-s];
end
end
end
end


A=imread('toyboy.jpg.');
B=decrease3(A,.75);
C=increase(B,4/3);
> image(255*C)
>> size(A)

ans =

160 128 3

>> size(B)

ans =

119 95 3

>> size(C)

ans =

157 125 3



















Very similar codes for 2 other pictures.