Friday, July 4, 2008

Rose_ Mosaic

Step(1)
Read the image and find the size

>> cd c:\Users\admin\pictures
>> A=imread('rose.jpg');
>> image(A), axis off

size(A)

ans =
500 500 3


Step(2)
Reduce the image to 10 X 10
Dividing by 50
Shrink it down to a 34 by 34 image(dividing the original image by 10)

Octave code as follows:


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
cd c:\users\admin\pictures
B=imread("dog.jpg");
B=double(B)/255;
B=zoom2(B,1/10);
imwrite("1/10dog.jpg",B(:,:,1),B(:,:,2),B(:,:,3));
size(B);
10 x 10

Step(3)
Reduce the colors to 27 of the reduced image

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
cd c:\users\admin\pictures
A=imread("reduceddog.jpg");
B=draw27(A);
C=double(B)/255;
imwrite("dog27.jpg",C(:,:,1),C(:,:,2),C(:,:,3));

Step(4)
Stretch the 27 color image 50 times


function Z=stretch2(simg,scale)
original_rows=size(simg,1);
original_cols=size(simg,2);
rows=floor(size(simg,1)*scale);
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("rose27.jpg"); B=stretch2(A,50); size(B) 500 500 3 C=double(B)/255; imwrite("strechedrose.jpg",C(:,:,1),C(:,:,2),C(:,:,3))

Step(5)

1 comment:

pdiddy said...

can you see this????