Sunday, June 1, 2008

Assignment 6

Question 1.

Use interpolation to skew and rotate bigT.

>> bigT = 255*ones(256);
>> bigT(30:79,64:191) = zeros(50,128);
>> bigT(50:199,111:146)=zeros(150,36);


function [trans] = interpolskewrot(matrix,factor,theta,translation)
trans = (1/2)*ones(256);
for x=1:256
for y=1:256
u=x*cos(theta)+y*sin(theta);
v=-x*sin(theta)+y*cos(theta);
up = mod(u,256)+1;
vp = mod(v,256)+1;
a=up;
b=mod((vp-factor*up),256)+1;
r =floor(u)+ translation;
s =floor(b);
if (r>0 && s>0 && r<256)
trans(x,y)=[1-(a-r),a-r]*[matrix(r,s) matrix(r,s+1);matrix(r+1,s) matrix(r+1,s+1)]*[1-(b-s);b-s]; end end end

imshow(interpolskewrot(bigT,2,7*pi/6,0))
>> imshow(interpolskewrot(bigT,2,7*pi/6,200))
>> imshow(interpolskewrot(bigT,2,7*pi/6,300))


The image after skew with s=2 and rotation 7pi/6. I added a vertical translation, since the image moves off the matrix.



Question 2.
Create a 256 by 256 matrix with 1's in the (i, i+1) position.
>> matrix = zeros(256);
>> for i =1:255
matrix(i,i+1)=1;
end
Question 3.
Compute the average color for the image.
a)
>> R = ones(100); G= tril(ones(100)); B=zeros(100);
>> A(:,:,1)=R;
>> A(:,:,2)=G;
>> A(:,:,3)=B;
>> imshow(A)

>> B = sum(sum(A))/100/100;
>> B
B(:,:,1) =
1
B(:,:,2) =
0.5050
B(:,:,3) =
0

>> C(:,:,1)= ones(100)*B(:,:,1);
>> C(:,:,2)= ones(100)*B(:,:,2);
>> C(:,:,3)= ones(100)*B(:,:,3);
>> imshow(C)








b)

>> f=ones(100,50);
d=(1/50)*ones(100,1)*[50:-1:1];
u=(1/50)*ones(100,1)*[1:1:50];
dh =(1/100)*ones(100,1)*[100:-1:51];
uh=(1/100)*ones(100,1)*[1:1:50];
z=zeros(100,50);
>> qd=(1/100)*ones(100,1)*[50:-1:1];
>> qu=(1/100)*ones(100,1)*[51:1:100];
>> R=[f,f,d,z,z,u,dh];
G=[z,u,f,dh,qd,z,z];
B=[z,z,z,uh,uh,qu,f];
>> M(:,:,1)=R;
>> M(:,:,2)=G;
>> M(:,:,3)=B;
>> imshow(M)
>> B = sum(sum(M))/100/350;
>> B

B(:,:,1) =
0.5393
B(:,:,2) =
0.3600
B(:,:,3) =
0.3236

>> D(:,:,1)= ones(100,1)*ones(1,350)*B(:,:,1);
>> D(:,:,2)= ones(100,1)*ones(1,350)*B(:,:,2);
>> D(:,:,3)= ones(100,1)*ones(1,350)*B(:,:,3);
>> imshow(D)








c)

>> imshow(Jade)
>> size(Jade)

ans =

534 800 3

>> sum(sum(Jade))/534/800;
>> P = sum(sum(Jade))/534/800;
>> P

P(:,:,1) =
0.3648
P(:,:,2) =
0.5267
P(:,:,3) =
0.1136

>> H(:,:,1)= ones(200)*P(:,:,1);
>> H(:,:,2)= ones(200)*P(:,:,2);
>> H(:,:,3)= ones(200)*P(:,:,3);
>> imshow(H)




>> imshow(bluelines)

>> size(bluelines)

ans =

530 800 3

>> J = sum(sum(bluelines))/530/800;
>> J

J(:,:,1) =
0.3083
J(:,:,2) =
0.4437
J(:,:,3) =
0.9478

>> V(:,:,1) = ones(200)*J(:,:,1);
>> V(:,:,2) = ones(200)*J(:,:,2);
>> V(:,:,3) = ones(200)*J(:,:,3);
>> imshow(V)


In images with one clear dominant color, the dominant color will be similar to average color. When there is more than one strong color present, the average color is a combination of dominant colors and will look different from the dominant colors.

No comments: