Sunday, June 1, 2008

Assignment #6

1. Skew and rotate an image using bilinear interpolation to determine an intensity value for each point.

Using the ideas discussed in class:

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














2. Create a 256x256 matrix with 1s in the (i,i+1) position and zeros


triu(ones(256),1)-triu(ones(256),2)

For the purposes of demonstration I will present a 6x6 matrix.

0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 0 0 0 0 0



3. Given a color, compute the average color. Compute the average color for the image with

a) R=ones(100);
G=tril(ones(100));
B=zeros(100);

A(:,:,1)=(ones(100));
A(:,:,2)=tril(ones(100));
A(:,:,3)=zeros(100);
imshow(A)
sum(sum(A))/100/100
ans =

ans(:,:,1) = 1
ans(:,:,2) = 0.50500
ans(:,:,3) = 0







































b)
R(:,:,1)=ones(256);
R(:,:,2)=ones(256,1)*[0:1:255]/255;
R(:,:,3)=zeros(256);
Y(:,:,1)=ones(256,1)*[255:-1:0]/255;
Y(:,:,2)=ones(256);
Y(:,:,3)=zeros(256);
G(:,:,1)=zeros(256);
G(:,:,2)=ones(256);
G(:,:,3)=ones(256,1)*[0:1:255]/255;
C(:,:,1)=zeros(256);
C(:,:,2)=ones(256,1)*[255:-1:0]/255;
C(:,:,3)=ones(256);
B(:,:,1)=ones(256,1)*[0:1:255]/255;
B(:,:,2)=zeros(256);
B(:,:,3)=ones(256);
M(:,:,1)=ones(256);
M(:,:,2)=zeros(256);
M(:,:,3)=ones(256,1)*[255:-1:0]/255;
K=[R,Y,G,C,B,M];
imshow(K)
size(K)

256 1536 3

sum(sum(K))/(256*1536)
ans =

ans(:,:,1) = 0.50000
ans(:,:,2) = 0.50000
ans(:,:,3) = 0.50000













































c)
pkg load image
cd C:\
A=imread("CokeCan.jpg")
size(A)
ans =

108 160 3
sum(sum(A))/(108*160)
ans =

ans(:,:,1) = 80.181
ans(:,:,2) = 148.30

ans(:,:,3) = 163.15





















pkg load image
cd C:\
B=imread("CHALLENGE.jpg")
size(B)
ans =

160 117 3
sum(sum(B))/(160*117)
ans =

ans(:,:,1) = 103.46
ans(:,:,2) = 106.67
ans(:,:,3) = 83.541















No comments: