0

Here is my codes for computing the average rank for each image from 1000 images. (We assume every 100 images are one catagory, e.g, 1-100, 101-200,....)

for z=1:1000
H{z}=imread(strcat(int2str(z-1),'.jpg'));

Im_red=H{z}(:,:,1);
Im_green= H{z}(:,:,2);
Im_blue= H{z}(:,:,3);
hist_im1=zeros(1,256); 
[h,w]=size(Im_red); 
for i=1:h   
for j=1:w
value_pixel1=Im_red(i,j)+1;
hist_im1(value_pixel1)=hist_im1(value_pixel1)+1;
end
end
hist_im2=zeros(1,256); 
[h,w]=size(Im_green); 
for i=1:h   
for j=1:w
value_pixel2=Im_green(i,j)+1;
hist_im2(value_pixel2)=hist_im2(value_pixel2)+1;
end
end
hist_im3=zeros(1,256); 
[h,w]=size(Im_blue); 
for i=1:h   
for j=1:w
value_pixel3 = Im_blue(i,j) + 1;
hist_im3(value_pixel3) = hist_im3(value_pixel3)+1;
end
end
Q{z}=[hist_im1, hist_im2, hist_im3];
end

for r=1:1000
for i=1:1000
a(r,i)=matchfunction(Q{r},Q{i});
end

for j=1:1000
b(r,j)=j;
end

L=[a;b];
end
for r=1:1000
B=[L(r,:);L(r+1000,:)];

[d1,d2] = sort(B(1,:),'descend');
C=B(:,d2);

aaa=C(1,:);
bbb=C(2,:);
ccc=zeros(1,1000);

for g=1:1000
if ((bbb(g)>=fix((r-1)/100)*100+1) & (bbb(g)<=ceil(r/100)*100))
ccc(g)=g;
end

end

ddd=sum(ccc(g))/100;

s(r)=ddd

end

avgrank(1)=sum(s(1:100))/100
avgrank(2)=sum(s(101:200))/100
avgrank(3)=sum(s(201:300))/100
avgrank(4)=sum(s(301:400))/100
avgrank(5)=sum(s(401:500))/100
avgrank(6)=sum(s(501:600))/100
avgrank(7)=sum(s(601:700))/100
avgrank(8)=sum(s(701:800))/100
avgrank(9)=sum(s(801:900))/100
avgrank(10)=sum(s(901:1000))/100
xCoordinates = 1:10;
plot(xCoordinates,avgrank,'b:*');

The match function is a function computes the match value of two histograms of two images with two histograms as input. You can see that Q{z} is the histogram. I think my problem is within here:

for g=1:1000
if ((bbb(g)>=fix((r-1)/100)*100+1) & (bbb(g)<=ceil(r/100)*100))
ccc(g)=g;
end

end

This is how I calculate the rank. So I just give the rank to ccc(g)

since for g runs from 1 to 1000, it will just be the rank we nee if we have

(bbb(g)>=fix((r-1)/100)*100+1) & (bbb(g)<=ceil(r/100)*100)

for a g. But why after I run this program I got the value of ccc is one thousand 0s? Why 0? Is there anything wrong with my way of getting the rank through ccc? And is there more errors of my code? I just get the average ranks and the ccc all 0 but cannot figure out why. Thanks in advance!!

Ian
  • 157
  • 1
  • 7

0 Answers0