-1

For doing a CBIR, I am computing the match value of two pictures. Below is my code. We can see that the input of this function is the name of two images and the output is the match value. I have the image with name "2.jpg" as my query image and I have 10 images in total with name "1.jpg" to "10.jpg". And I need to get the match values for any image among the 10 images with "2.jpg". So how can I make a loop and using the below function to get the 10 values and save them in an array? I don't want to manually change the name of the pictures in the function, and more importantly, how can I save the 10 match values in an array? Thanks in advance!

function matchfunction(C,D)
first=imread(C);
Im_red=first(:,:,1);
Im_green=first(:,:,2);
Im_blue=first(:,:,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
second=imread(D);
Im_red2=second(:,:,1);
Im_green2=second(:,:,2);
Im_blue2=second(:,:,3);
hist_im4=zeros(1,256); 
[h,w]=size(Im_red2); 
for i=1:h   
for j=1:w
value_pixel4=Im_red2(i,j) + 1;
hist_im4(value_pixel4)=hist_im4(value_pixel4)+1;
end
end 
hist_im5=zeros(1,256); 
[h,w]=size(Im_green2); 
for i=1:h   
for j=1:w
value_pixel5=Im_green2(i,j) + 1;
hist_im5(value_pixel5)=hist_im5(value_pixel5)+1;
end
end
hist_im6=zeros(1,256); 
[h,w]=size(Im_blue2); 
for i=1:h   
for j=1:w
value_pixel6=Im_blue2(i,j) + 1;
hist_im6(value_pixel6)=hist_im6(value_pixel6)+1;
end
end
A=[hist_im1, hist_im2, hist_im3];
B=[hist_im4, hist_im5, hist_im6];
[Aa,Ab]=size(A);
for i=1:Ab
H(i)=min(A(i),B(i));
end
HI=sum(H);
HI/sum(B)
i_a_n
  • 139
  • 1
  • 1
  • 8

1 Answers1

0

Your matchfunction wont work because you haven't set a to be anything, so it won't output anything, but if you fix that you can just do a simple for loop. (matchfunction(2,i) should compare "2.jpg" to "i.jpg", I'm not sure if that is the right syntax for your function though)

for i=1:10
    a(i)=mathcfunction(2,i);
end

Then the i-th element of a is the match value for images 2 and i.

David
  • 8,449
  • 1
  • 22
  • 32
  • I tried for i=1:10 a(i)=matchfunction('2.jpg',strcat(int2str(i),'.jpg')); end But it shows: Error using matchfunction Too many output arguments. How to fix this? – i_a_n Sep 16 '14 at 04:07
  • I want to save all the output values in an array. – i_a_n Sep 16 '14 at 04:10
  • You have to fix your `matchfunction` so that it works first! At the moment `matchfunction` does not give any outputs at all!! For a simple example, run this little for loop: `a=[];for i=1:5;a(i)=i^2;end;a` this should show how to save results into an array. – David Sep 16 '14 at 06:10