Thursday, July 3, 2008

The "large pixels"

Here are the original images which were resized to be the 15 x 15 pixel images in the photmosaic. I tried to use as many "prairie" images as I could in keeping with the theme of the big red elevator.

Wednesday, July 2, 2008

Photomosaic... Finally





Here it is...after days of messing about, trying to find a short set of commands to define and read in/replace the 27 small pictures (with no success).

The images are in reverse order: final output, 27 colours, enlarged, 40 x 40 matrix, and the original image.

The original is from a photo I took in 2003 on a trip "home" with my son and my mother. The elevator is located a mile or so down the road from the farm I lived on as a child. The old red elevators have all but disappeared (as has the town of Nut Mountain, Sask.) but a few were sold to private owners and maintained.

I will post the array of small pictures I used as soon as I can organize it for the blog.



The Code:


#Set up Octave

pkg load image
cd 'C:\pictures'

#read in the original image

B=imread ("Nutmountainsquare.jpg");
B=double(B)/255;
size(B)
imshow(B)

#shrink the image

function Step1 = PM1(A,f)
rows=floor(size(A,1)*f);
cols=floor(size(A,2)*f);
for i=1:rows;
for j=1:cols;
a=round(i/f);
b=round(j/f);
Step1(i,j,:)=A(a,b,:);
end;
end;
endfunction

PM2=PM1(B,1/12.5);
size(PM2)
imshow(PM2)

#reduce to 27 colours

PM3=floor(255*(PM2)/86)*86 + 42;
imshow(double(PM3)/255)
size(PM3)

#enlarge the image

function largeimage=grow1(smallimage,f)
rows=size(smallimage,1);
cols=size(smallimage,2);

Mp=floor(size(smallimage,1)*f);
Np=floor(size(smallimage,2)*f);

for i=0:(Mp-1);
for j=0:(Np-1);
a=round((i/f)+1);
b=round((j/f)+1);

if (a(greaterthan)0) & (a(lessthan)rows) & (b(greaterthen)0) & (b(lessthan)cols)
largeimage(i+1,j+1,:)=smallimage(a,b,:);
end;
end;
end;
endfunction;


PM4=grow1(PM3,15);
size(PM4)
imshow(double(PM4)/255)

#read in the 27 pictures

cd 'C:\pictures\27pics'

B01=imread('one.jpg');
B02=imread('two.jpg');
B03=imread('three.jpg');
B04=imread('four.jpg');
B05=imread('five.jpg');
B06=imread('six.jpg');
B07=imread('seven.jpg');
B08=imread('eight.jpg');
B09=imread('nine.jpg');
B10=imread('ten.jpg');
B11=imread('eleven.jpg');
B12=imread('twelve.jpg');
B13=imread('thirteen.jpg');
B14=imread('fourteen.jpg');
B15=imread('fifteen.jpg');
B16=imread('sixteen.jpg');
B17=imread('seventeen.jpg');
B18=imread('eighteen.jpg');
B19=imread('nineteen.jpg');
B20=imread('twenty.jpg');
B21=imread('twentyone.jpg');
B22=imread('twentytwo.jpg');
B23=imread('twentythree.jpg');
B24=imread('twentyfour.jpg');
B25=imread('twentyfive.jpg');
B26=imread('twentysix.jpg');
B27=imread('twentyseven.jpg');

#create oneD array of small pictures

Y=[B01,B02,B03,B04,B05,B06,B07,B08,B09,B10,B11,B12,B13,B14,B15,B16,B17,B18,B19,B20,B21,B22,B23,B24,B25,B26,B27];

#create matrix of 27 rgb values

A01(:,:,1)=42;
A01(:,:,2)=42;
A01(:,:,3)=42;

A02(:,:,1)=42;
A02(:,:,2)=42;
A02(:,:,3)=128;

A03(:,:,1)=42;
A03(:,:,2)=42;
A03(:,:,3)=214;

A04(:,:,1)=42;
A04(:,:,2)=128;
A04(:,:,3)=42;

A05(:,:,1)=42;
A05(:,:,2)=128;
A05(:,:,3)=128;

A06(:,:,1)=42;
A06(:,:,2)=128;
A06(:,:,3)=214;

A07(:,:,1)=42;
A07(:,:,2)=214;
A07(:,:,3)=42;

A08(:,:,1)=42;
A08(:,:,2)=214;
A08(:,:,3)=128;

A09(:,:,1)=42;
A09(:,:,2)=214;
A09(:,:,3)=214;

A10(:,:,1)=128;
A10(:,:,2)=42;
A10(:,:,3)=42;

A11(:,:,1)=128;
A11(:,:,2)=42;
A11(:,:,3)=128;

A12(:,:,1)=128;
A12(:,:,2)=42;
A12(:,:,3)=214;

A13(:,:,1)=128;
A13(:,:,2)=128;
A13(:,:,3)=42;

A14(:,:,1)=128;
A14(:,:,2)=128;
A14(:,:,3)=128;

A15(:,:,1)=128;
A15(:,:,2)=128;
A15(:,:,3)=214;

A16(:,:,1)=128;
A16(:,:,2)=214;
A16(:,:,3)=42;

A17(:,:,1)=128;
A17(:,:,2)=214;
A17(:,:,3)=128;

A18(:,:,1)=128;
A18(:,:,2)=214;
A18(:,:,3)=214;

A19(:,:,1)=214;
A19(:,:,2)=42;
A19(:,:,3)=42;

A20(:,:,1)=214;
A20(:,:,2)=42;
A20(:,:,3)=128;

A21(:,:,1)=214;
A21(:,:,2)=42;
A21(:,:,3)=214;

A22(:,:,1)=214;
A22(:,:,2)=128;
A22(:,:,3)=42;

A23(:,:,1)=214;
A23(:,:,2)=128;
A23(:,:,3)=128;

A24(:,:,1)=214;
A24(:,:,2)=128;
A24(:,:,3)=214;

A25(:,:,1)=214;
A25(:,:,2)=214;
A25(:,:,3)=42;

A26(:,:,1)=214;
A26(:,:,2)=214;
A26(:,:,3)=128;

A27(:,:,1)=214;
A27(:,:,2)=214;
A27(:,:,3)=214;


#creat a oneD array of colour chips

X=[A01,A02,A03,A04,A05,A06,A07,A08,A09,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22,A23,A24,A25,A26,A27];

#replace big "pixels" with small colour pictures

for i = 1:15:578
for j = 1:15:578
for m = 1:27

if PM4(i,j,:)==X(1,m,:)
PM4(i:i+15-1,j:j+15-1,:)=Y(1:15,(m-1)*15+1:m*15,:);
end;
end;
end;
end;

imshow(double(PM4)/255)

Saturday, June 7, 2008

Assignment #7






function smallimage=shrink2(largeimage,f);

Mp=floor(size(largeimage,1)*f-1);
Np=floor(size(largeimage,2)*f-1);

smallimage(:,:,1)=zeros(Mp-1,Np-1);
smallimage(:,:,2)=zeros(Mp-1,Np-1);
smallimage(:,:,3)=zeros(Mp-1,Np-1);


for i=1:(Mp-1)
for j=1:(Np-1)

a=round(i/f);
b=round(j/f);
smallimage(i,j,:)=largeimage(a,b,:);
end;
end;
endfunction;



A=imread("image.jpg");

B=shrink2((double(A)/255),f);
function smallimage=shrink3(largeimage,f)


Mp=floor(size(largeimage,1)*f);
Np=floor(size(largeimage,2)*f);

smallimage(:,:,1)=zeros(Mp-1,Np-1);
smallimage(:,:,2)=zeros(Mp-1,Np-1);
smallimage(:,:,3)=zeros(Mp-1,Np-1);


for i=1:(Mp-1);
for j=1:(Np-1);
a=i/f;
b=j/f;

r=floor(a);
s=floor(b);

for k = 1:3;

smallimage(i,j,k)=[1-a+r, a-r]*double([largeimage(r,s,k),largeimage(r,s+1,k);largeimage(r+1,s,k),largeimage(r+1,s+1,k)])*[1-b+s;b-s];

end;
end;
end;
endfunction;



A=imread("image.jpg");

B=shrink3((double(A)/255),0.75);


Monday, June 2, 2008

Assignment #6-question 3

Assignment 6 - 3 b)


pkg load image

cd 'C:\pictures'
A=imread("Rainbow.jpg");
B=double(A)/255;
size(B)

ans =
109 200 3

aveB=sum(sum(B))/109/200

ans(:,:,1)=0.56770
ans(:,:,2)=0.34527
ans(:,:,3)=0.30058


aveB(:,:,1)=0.56770
aveB(:,:,2)=0.34527
aveB(:,:,3)=0.30058

imshow(aveB)


6 -3 b)

Find the average colour of two images from the web.

C=imread("green.jpg");
D=double(C)/255;
imshow(D)
size(D)

ans =
110 160 3

aveD=sum(sum(D))/110/160

ans(:,:,1)=0.46077
ans(:,:,2)=0.66349
ans(:,:,3)=0.069944


aveD(:,:,1)=0.46077
aveD(:,:,2)=0.66349
aveD(:,:,3)=0.069944

imshow(aveD)


E=imread("blue.jpg");
F=double(E)/255
imshow(F)
size(F)
ans =

106 160 3

aveF=sum(sum(F))/106/160

ans(:,:,1)=0.24725
ans(:,:,2)=0.35670
ans(:,:,3)=0.76474


aveF(:,:,1)=0.24725
aveF(:,:,2)=0.35670
aveF(:,:,3)=0.76474
imshow(aveF)

When the original image is predominately one colour, the average colour is similar. When the original image has many colours, the average colour is less predictable.