Thursday, June 19, 2008

Assign 9, Q5 - And Photomosaic start...

Here we had to change spidey to a greyscale image with only 16 intensity values.

I thought that the image would be even more grainy...however the new 16 intensity values greyscale image had more detail. Perhaps because there are now less intensity values to choose from and so not much shading could take place but more detail in certain areas can now be seen.



The lessening of intensity values with grey scale images and the 'apparent increasing' of detail seems to work "in reverse" for colour images as can be noted in my comments of Assignment9 Question 1 (below).

Here is the start of my photomosaic...

I tried to use the spiderman image but when I shrunk it, reduced the colours, and enlarged it...the image was too distorted.



So I used a different picture...the ATARI icon.

Step 1:




step 2:




Step 3:



Step 4 & 5:

I used Photoshop to adjust the image size via pixels because I had to 'crop'/grap the 'small pictures' I wanted from a screen grab. I want to use the pac-man ghosts and ms. pac-man as my small pictures.












Here is part of my octave code:

# step 1 - shrink image - the size of the original is 200 by 200 pixels...

function [smallimage]=shrink2(pic,f);
Mp = floor(size(pic,1)*f);
Np = floor(size(pic,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=0:(Mp-1);
for j=0:(Np-1);
a=floor((i/f)+1);
b=floor((j/f)+1);
if a 0 & a<(size(pic,1)) & b>0 & b<(size(pic,2));
smallimage(i+1,j+1,:)=pic(a,b,:);
end;
end;
end;
endfunction;

# To show image which was scaled down by factor f = 0.1, the resulting image will be 20 by 20 pixels.
A=imread("logo.png");
B=shrink2(A,.1);
C=double(B)/255;
imwrite("logo1.png",C(:,:,1),C(:,:,2),C(:,:,3))

# step 2 - reduce colour to 27...

A=imread("logo1.png");
B = floor(double(A)/86)*86+42;
imwrite("logo2.png",double(B)(:,:,1)/255, double(B)(:,:,2)/255, double(B)(:,:,3)/255);

# step 3 - enlarge...

function [smallimage]=enlarge(pic,f);
Mp = floor(size(pic,1)*f);
Np = floor(size(pic,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=0:(Mp-1);
for j=0:(Np-1);
a=floor((i/f)+1);
b=floor((j/f)+1);
if a > 0 & a < (size(pic,1)) & b > 0 & b < (size(pic,2));
smallimage(i+1,j+1,:)=pic(a,b,:);
end;
end;
end;
endfunction;

A=imread("logo2.png");
B=enlarge(A,20);
C=double(B)/255;
imwrite("logo3.png",C(:,:,1),C(:,:,2),C(:,:,3));


# Put pixels in...

a=imread("logo3.png");
p=imread("pink.png");
r=imread("red.png");
y=imread("mspac.png");

# Pink...(column, row, :) pixel coords...

a(140:159,300:319,:)=p;
a(160:179,300:319,:)=p;
a(180:199,300:319,:)=p;
a(200:219,300:319,:)=p;

a(140:159,320:339,:)=p;
a(160:179,320:339,:)=p;
a(180:199,320:339,:)=p;
a(200:219,320:339,:)=p;



a(140:159,380:399,:)=p;
a(160:179,380:399,:)=p;
a(180:199,380:399,:)=p;
a(200:219,380:399,:)=p;

a(140:159,400:419,:)=p;
a(160:179,400:419,:)=p;
a(180:199,400:419,:)=p;
a(200:219,400:419,:)=p;

a(140:159,420:439,:)=p;
a(160:179,420:439,:)=p;
a(180:199,420:439,:)=p;
a(200:219,420:439,:)=p;



a(140:159,480:499,:)=p;
a(160:179,480:499,:)=p;
a(180:199,480:499,:)=p;
a(200:219,480:499,:)=p;

a(140:159,500:519,:)=p;
a(160:179,500:519,:)=p;
a(180:199,500:519,:)=p;
a(200:219,500:519,:)=p;


# red pixels coords...

a(80:99,300:319,:)=r;
a(80:99,320:339,:)=r;

a(80:99,380:399,:)=r;
a(80:99,400:419,:)=r;
a(80:99,420:439,:)=r;

a(80:99,480:499,:)=r;
a(80:99,500:519,:)=r;


# yellow pixels coords...

a(600:619,160:179,:)=y;
a(600:619,180:199,:)=y;
a(600:619,200:219,:)=y;
a(600:619,220:239,:)=y;
a(600:619,240:259,:)=y;

a(620:639,120:139,:)=y;
a(620:639,140:159,:)=y;
a(620:639,160:179,:)=y;
a(620:639,180:199,:)=y;
a(620:639,200:219,:)=y;
a(620:639,220:239,:)=y;

a(640:659,80:99,:)=y;
a(640:659,100:119,:)=y;
a(640:659,120:139,:)=y;
a(640:659,140:159,:)=y;
a(640:659,160:179,:)=y;
a(640:659,180:199,:)=y;
a(640:659,200:219,:)=y;


a(660:679,80:99,:)=y;
a(660:679,100:119,:)=y;
a(660:679,120:139,:)=y;
a(660:679,140:159,:)=y;
a(660:679,160:179,:)=y;
a(660:679,180:199,:)=y;


a(600:619,380:399,:)=y;
a(620:639,380:399,:)=y;
a(640:659,380:399,:)=y;
a(660:679,380:399,:)=y;

a(600:619,400:419,:)=y;
a(620:639,400:419,:)=y;
a(640:659,400:419,:)=y;
a(660:679,400:419,:)=y;

a(600:619,420:439,:)=y;
a(620:639,420:439,:)=y;
a(640:659,420:439,:)=y;
a(660:679,420:439,:)=y;


f=double(a)/255;
imwrite("atari5.png",f(:,:,1),f(:,:,2),f(:,:,3));

here is the resulting mosaic to date:

Assign 9, Q4

Here we had to change the spidey image into a greyscale of only 64 intensity values...here is where the image ceases to look cool...

Assign 9, Q3

Change spidey into a greyscale image...

Assign 9, Q2

Will now convert the spidey image to contain only 27 colours.

Here are the original, 64, and 27 colour images.






As you can guess...with fewer colours to represent the image, the less detail and shading is apparent in comparison with the original image.

Assign 9, Q1

Really excited to try the photomosaic so will be using new images for this assignment...just want to see how they turn out.

Here is the original image of our friendly neighbourhood spider-man (okay he doesn't look THAT friendly).



Here is the resulting image after we have converted the image to only 64 colours.



way cool!

Assign 8, Q5

Here I used the nearest neighbour approximation function that I used in assignment #7 and applied it 4 times (f=0.8, 0.6, 0.4, 0.2) the large image just remains the same at f=1 or the original sized image.

Then layered the pics one on top of the other.

octave:10> a=imread("start.jpg");
octave:11> b=shrinkimg(a,0.8);
octave:12> c=shrinkimg(a,0.6);
octave:13> d=shrinkimg(a,0.4);
octave:14> e=shrinkimg(a,0.2);
octave:15> a1=double(a)/255;
octave:16> b1=double(b)/255;
octave:17> c1=double(c)/255;
octave:18> d1=double(d)/255;
octave:19> e1=double(e)/255;
octave:20> a1(52:459,78:690,:)=b1;
octave:21> a1(103:408,155:613,:)=c1;
octave:22> a1(155:357,231:536,:)=d1;
octave:23> a1(206:306,308:459,:)=e1;
octave:24> f=double(a1)/255;
octave:25> imwrite("nstart.jpg", f(:,:,1),f(:,:,2),f(:,:,3));
octave:26> imwrite("n1start.jpg",a1(:,:,1),a1(:,:,2),a1(:,:,3));

In a new terminal you can imshow:

a=imread("n1start.jpg");
b=double(a)/255;
imshow(b);

Here is the image:

Wednesday, June 18, 2008

Assign 8, Q2

Use nearest neighbour approximation (n.a.) to 'enlarge' a colour image using f=1/f.

Note that I could change my n.a. function from f's to 1/f's or I could just take an 'f' and plug it into 1/f.

Ex: f=0.5=1/2 so 1/f=1/(1/2)=2.

Therefore I can use my same n.a. function used in assignment #7, Q2, but use values of f>1.

Here is how f=1.2 looks like: