0

我编写了一个 matlab 函数,使我能够从用户那里获取图像的名称,并将其与现有图像进行比较,并显示是否匹配。

function matchin
handles = guidata(gcbo);
set(handles.h_text,'String','performing matching...');
[image1, pathname]= uigetfile('*.bmp','Open An Fingerprint image');
Directory = fullfile ('F:','matlab','bin');
D = dir(fullfile(Directory,'*.bmp'));
set(handles.h_text,'String','matching complete....');
for i = 1:numel(D)
   if strcmp(image1,D(i).name)
       disp('matched');
   else       
        disp('not matched');
   end

end

上面的代码检查文件名是否存在,但我现在想比较图像本身而不是文件名。我该怎么做?请帮助..

问候

普里亚

4

2 回答 2

1

你的函数应该是这样的:

function image1=matchin

[image1, pathname]= uigetfile('*.bmp','Open An Fingerprint image');
Directory = fullfile ('F:','matlab','bin');
D = dir(fullfile(Directory,'*.bmp'));
imcell = {D.name}';
for i = 1:numel(D)
  if strcmp(image1,imcell{i})
  disp('matched');
else
    disp('not matched');
  end
end

end

您可以使用{D.name}'. 至少当我在带有图像的文件夹中尝试它时,它对我来说就是这样。

于 2013-03-20T15:45:47.257 回答
1

使用strcmp而不是==比较未知长度的字符串。您可以将其更改for loop为:

D = dir(Directory);
for i = 1:numel(D)
   if strcmp(image1,D(i).name)
       disp('matched');
   else
       disp('not matched');
   end
end
于 2013-03-20T15:33:24.980 回答