2016-02-18 34 views
-4

例如,我在我的目录中有100张图像,其中'x'图像相同,我想知道x的值。如何使用MATLAB将单个图像与多个图像进行匹配?

+2

同为一精确复制? –

+0

@AnderBiguri 我的意思是我想知道的X.即价值,我希望看到所有图片! – Raju

+1

什么?所有图片= 100,然后x = 100?你提出的评论与这个问题是不一致的。你能解释一下你的问题是什么? –

回答

1

如果我正确理解你的问题,所有你想要做的是算多少图像是完全一样的,有些目标图像,那么这应该工作...

%directory where images are stored 
directory = 'Directory_To_Images'; 
files = dir(directory); 

%total number of matches 
numMatches = 0; 

%The Real image, the image you wish to test against 
RealImage = imread('Target_Image.jpg'); 

%go through all files in the directory 
for i = 1 : length(files) 
[pathstr,name,ext] = fileparts(files(i).name); 

%test to make sure its a JPG image (you may need to modify this if you have 
%multiple file types 
if (strcmp(ext,'.jpg')) 
    %check if the images match 
    if(isMatch(RealImage, [directory '\' name ext])) 
     numMatches = numMatches+1; 
    end 
end 
end 

sprintf('Number of matches: %s', num2str(numMatches)) 

这里是失踪功能:

function[result] = isMatch(RealImage, TestImage) 

testImage = imread(TestImage); 
if (sum(sum(sum(RealImage == testImage))) == size(RealImage,1) * size(RealImage,2) * size(RealImage,3)) 
    result = true; 
else 
    result = false; 

end 
+0

让我们假设一个场景我有一个10分钟的视频剪辑。因为我想知道视频中某个特定人物的存在(总时间)。为此,我提取了视频中的所有帧,现在我想与输入图像匹配,然后根据时间计算帧,例如。说24fps ...如果500张照片匹配500/24秒。有没有其他方法可以找到?在此先感谢 – Raju

+0

@KanakaRaju,让我们假设你学会使用计算器。你问一两件事,得到了你问什么有用的答案(500个图像目录),现在它就像他们浪费了他们的(带薪)时间写,所以您可以修改规则.. –

1
% Reference image 
img_ref = imread('img_ref.jpg'); 

% Create an variable for alloc the path 
img_path ='/your/dir/of/images/' 

% Create an variable struct, for searching files with .jpg extension 
names = dir(fullfile(img_path, '*.jpg')); 


% Counts the number of images on the path 
n_imgs = numel(names); 

for n = 1:n_imgs 
    full_name = fullfile(img_path, names(n).name); 
    your_imgs = imread(full_name); 

    r = isMatch(img_ref,your_imgs); 
    disp(r) 
end 

可以使用上面创建的功能由Rob F.

+0

让我们假设一个场景我有一个视频剪辑10分钟。因为我想知道视频中某个特定人物的存在(总时间)。 为此,我提取了视频中的所有帧,现在我想与输入图像匹配,然后根据时间计算帧,例如。说24fps ...如果500张照片匹配500/24秒。有没有其他方法可以找到? 在此先感谢 – Raju

+0

@KanakaRaju,让我们假设你学会使用计算器。你问了一件事,并为你提出的问题(目录中的500张图片)得到了有用的答案,现在就像他们浪费了他们的(无偿)时间写作一样,以便你可以改变规则。 –