-1

为了进行 CBIR,我正在计算两张图片的匹配值。下面是我的代码。我们可以看到这个函数的输入是两个图像的名称,输出是匹配值。我有一个名为“2.jpg”的图像作为我的查询图像,我总共有 10 个图像,名称为“1.jpg”到“10.jpg”。我需要获取 10 个带有“2.jpg”的图像中任何图像的匹配值。那么如何进行循环并使用以下函数获取 10 个值并将它们保存在数组中?我不想在函数中手动更改图片的名称,更重要的是,如何将10个匹配值保存在一个数组中?提前致谢!

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)
4

1 回答 1

0

matchfunction不会工作,因为你没有设置a任何东西,所以它不会输出任何东西,但如果你修复它,你可以做一个简单的for循环。(matchfunction(2,i)应该将“2.jpg”与“i.jpg”进行比较,但我不确定这是否是您函数的正确语法)

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

那么 的i-th 元素a是图像 2 和 的匹配值i

于 2014-09-16T03:50:56.163 回答