Thursday, May 29, 2008

Octave - Image Package

(3)b) X=imread('facebookrainbow.jpg'); imshow(X) displays the following:

Computing the average color for this rainbow image:
Avg(R) = 15357868/255*225*310 = 0.86347
Avg(G) = 14141756/255*225*310 = 0.79509
Avg(B) = 13886570/255*225*310 = 0.78075.

The average color chip is a "light mauve", due to the components (220, 203, 199). This is different than the average color I obtained from my rainbow image, which was grey, with average color components (128, 128, 128). The average color function is blending all of the color components, I think.

(3)c) Here are the images, as generated by Octave-3.0.1:




B=imread('asst6_3c2.jpg')
imshow(B)

size(B)
ans = 107 160 3
sum(sum(B))
ans =
ans(:,:,1) = 1418726
ans(:,:,2) = 2754025
ans(:,:,3) = 2414097
max(B)
ans =
ans(:,:,1) = 255
ans(:,:,2) = 242
ans(:,:,3) = 225
Avg(R) = 1418726/255*107*160 = 0.32498
Avg(G) = 2754025/242*107*160 = 0.66474
Avg(B) = 2414097/255*107*160 = 0.62671

{used bucket fill in GIMP to generate Average Color}

  • R = 83
  • G = 170
  • B = 160

To display the Average Color, Green/Blue:

V2=255*ones(256);

V2(:,:,1)=0.32498*ones(256);
V2(:,:,2)=0.66474*ones(256);
V2(:,:,3)=0.62671*ones(256);
imshow(V2).


A=imread('asst6_3c1.jpg')
imshow(A)

size(A)
ans = 108 160 3
sum(sum(A))
ans =
ans(:,:,1) = 2158047
ans(:,:,2) = 1096316
ans(:,:,3) = 1048465
max(A)
ans =
ans(:,:,1) = 255
ans(:,:,2) = 255
ans(:,:,3) = 255
Avg(R) = 2158047/255*108*160 = 0.48975
Avg(G) = 1096316/255*108*160 = 0.24880
Avg(B) = 1048465/255*108*160 = 0.23794

{used bucket fill in GIMP to generate Average Color}

  • R = 125
  • G = 64
  • B = 61

To display the Average Color, "Maroon":

V1=255*ones(256);
V1(:,:,1)=0.48975*ones(256);
V1(:,:,2)=0.24880*ones(256);
V1(:,:,3)=0.23794*ones(256);
imshow(V1).

Based on the color components of the average colors, the color (as seen by my eye) of the 'average color chips' do not surprise me. As compared to the dominant colors when viewing the images, the average color chips are close to the dominant colors, but look more to be a blend of the colors in the original images.

Wednesday, May 28, 2008

Octave - Part 3

(1) To skew bigT by a factor of 1 pixel and rotate bigT 5*pi/4 degrees:

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:
T=zeros(256);
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(:,:,1)=ones(100);

X(:,:,2)=tril(ones(100));

X(:,:,3)=zeros(100);

imshow(X).

size(X)

ans= 100 100 3

sum(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 = 1

ans(:,:,2) = displays columns 1 through 100 with entries = 1

ans(:,:,3) = displays columns 1 through 100 with entries = 0

Avg(R) = 10 000/1*100*100 = 1

Avg(G) = 5050/1*100*100=0.505

Avg(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) = 196608

ans(:,:,2) = 196608

ans(:,:,3) = 196608

max(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 1

ans(:,:,3) = displays columns 1 through 1536 with entries between 0 and 1

Avg(R)=Avg(G)=Avg(B)= 196608/1*256*1536 = 0.5

To 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.