Sunday, June 1, 2008

Assignment 6







Assignment 6


(1) Rotation of bigT from Assignment 5 by using linear interpolation

T=255*ones(256);
T(30:79,64:191)=zeros(50,128);
T(50:199,111:146)=zeros(150,36);
T1=ones(256);
for x=1:256
for y=1:256
u=x*cos(2*pi/3)+y*sin(2*pi/3);
v=-x*sin(2*pi/3)+y*cos(2*pi/3);
a=u; b=mod(v-u,256)+1;
r=floor(a); s=floor(b);
if ((r>0)&(r<256)&(s>0)&(s<256))
T1(x,y)=[1-(a-r),a-r]*[T(r,s),T(r,s+1);T(r+1,s),T(r+1,s+1)]*[1-(b-s);b-s];
endif
endfor
endfor
imshow(T1)



Comparing with the picture obtained in assessment 5, using interpolation Q3 we have now obtained a nice, smooth image.

(2) Creating a 256x256 square matrix such that each element (i,i+1) is 1 and the rest of the elements are 0 (0<=i<=255).

tril(ones(256),1)-tril(ones(256))

or:

A=zeros(256);
for i=1:256
for j=1:256
if (j==i+1) A(i,j)=1;
end
end
end

(3) Determining the average color of a picture
a)

A(:,:,1)=ones(100);
A(:,:,2)=tril(ones(100));
A(:,:,3)=zeros(100);
B=255*A;
imshow(B)


size(B)
ans =

100 100 3
sum(sum(B))
ans =

ans(:,:,1) = 2550000
ans(:,:,2) = 1287750
ans(:,:,3) = 0


C=sum(sum(B))/size(A,1)/size(A,2)
C =

ans(:,:,1) = 255
ans(:,:,2) = 128.78
ans(:,:,3) = 0

for i=1:3
average(:,:,i)=C(i)*ones(100);
end
imshow(average)

Note:
If I do imshow(double(average)/255) I obtain a black screen


b) Rainbow image Math 5300:
Picture from the Assignment 4:


pkg load image
cd C:\
A=imread("Rainbow.jpg");
imshow(A)

Note: If I do:
imshow(double(A)/255) I get a black screen

size(A)
ans =

89 129 3

sum(sum(A))
ans =

ans(:,:,1) = 2076422
ans(:,:,2) = 1669866
ans(:,:,3) = 1580322

B=sum(sum(A))/size(A,1)/size(A,2)
B =

ans(:,:,1) = 180.86
ans(:,:,2) = 145.45
ans(:,:,3) = 137.65

for i=1:3
average(:,:,i)=B(i)*ones(100);
end
imshow(average)

Average color = white screen

Note: If I do imshow(double(average)/255) I get a black screen.

c)
1st Picture: “Peas”



pkg load image
cd C:\
A=imread("Peas.jpg");
imshow(A)


Note: If I do imshow(double(A)/255) I get a black screen.



size(A)
ans =

113 160 3

sum(sum(A))
ans =

ans(:,:,1) = 590114
ans(:,:,2) = 1866276
ans(:,:,3) = 273125

B=sum(sum(A))/size(A,1)/size(A,2)
B =

ans(:,:,1) = 32.639
ans(:,:,2) = 103.22
ans(:,:,3) = 15.106

for i=1:3
average(:,:,i)=B(i)*ones(100);
end
imshow(average)

2nd Picture: “Lit Tree”




pkg load image
cd C:\
A=imread("LitTree.jpg");
imshow(A)

size(A)
ans =

625 444 3

sum(sum(A))
ans =

ans(:,:,1) = 14070613
ans(:,:,2) = 19127011
ans(:,:,3) = 9894485


B=sum(sum(A))/size(A,1)/size(A,2);
B =

ans(:,:,1) = 50.705
ans(:,:,2) = 68.926
ans(:,:,3) = 35.656

for i=1:3
average(:,:,i)=B(i)*ones(100);
end
imshow(average)

Note: If I do imshow(double(average)/255) I get a black screen.


1 comment:

Mike Zabrocki said...

Violeta,
I am not confident of the results of imshow from your computer. This is not a serious bug, however, you should only use the two commands imread and imwrite, then it should work fine.

I know you are switching to Matlab, but I am not confident of that working out any better.
-Mike