bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50:128);
bigT(50:199,111:146)=zeros(150,36);
newbigT=255*ones(256);
for x=1:256;
for y=1:256;
u=x*cos(5*pi/4)+y*sin(5*pi/4);
v=-x*sin(5*pi/4)+y*cos(5*pi/4);
up=mod(u,256) + 1;
vp=mod(v,256) + 1;
a=up;
b=mod((vp-1*up),256) + 1;
r=floor(a);
s=floor(b);
if ((r>0) & (r<256)
(s>0) & (s<256));
newbigT(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(newbigT).
(2) To create a 256 x 256 matrix with 1s in the (i, i+1) position and zeros elsewhere:
- Using a for loop, as I did in Assignment #4:
for i=1:256;
for j=1:256;
if (j-i)==1;
T(i,j)=1;
endif;
endfor;
endfor;
T.
- Using triu(M,k):
triu(ones(256),1) - triu(ones(256),2)
(3) Calculating Average Color:
X(:,:,3)=zeros(100);
imshow(X).size(X)
ans= 100 100 3sum(sum(X))
ans =ans(:,:,1)=10 000
ans(:,:,2)=5050
ans(:,:,3)=0
max(X)ans =
ans(:,:,1) = displays columns 1 through 100 with entries = 1ans(:,:,2) = displays columns 1 through 100 with entries = 1
ans(:,:,3) = displays columns 1 through 100 with entries = 0Avg(R) = 10 000/1*100*100 = 1
Avg(G) = 5050/1*100*100=0.505Avg(B) = 0/0*100*100 = 0
To display the average color (orange image above):A(:,:,1)=ones(256);
A(:,:,2)=0.505*ones(256);A(:,:,3)=zeros(256);
X=255*A;imshow(X).
b) Using X=[R, Y, G, C, B, M], where R, Y, G, C, B, and M are defined in Question #18, Assignment 4, as my Rainbow Image (no, Cyan isn't really visible on the facebook page, and my Magenta doesn't entirely look like the Purple component that is on the facebook page...I am curious to compare the Average colors generated using my Rainbow Image and those from the Facebook Rainbow when I can get imread to work).First, define R, Y, G, C, B, M;
X=[R,Y,G,C,B,M];
size(X)ans = 256 1536 3
sum(sum(X))ans =
ans(:,:,1) = 196608ans(:,:,2) = 196608
ans(:,:,3) = 196608max(X)
ans =ans(:,:,1) = displays columns 1 through 1536 with entries between 0 and 1
ans(:,:,2) = displays columns 1 through 1536 with entries between 0 and 1ans(:,:,3) = displays columns 1 through 1536 with entries between 0 and 1
Avg(R)=Avg(G)=Avg(B)= 196608/1*256*1536 = 0.5To display the average color:
A(:,:,1)=0.5*ones(256);
A(:,:,2)=0.5*ones(256);
A(:,:,3)=0.5*ones(256);
X=255*A; {this line not necessary; 128*A works displays the same image}
imshow(X).
This is a black screen, but shouldn't it be grey?...not worth uploading.
No comments:
Post a Comment