例如,我的目录中有100个图像,其中'x'图像相同,我想知道x的值。
答案 0 :(得分: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
答案 1 :(得分: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.
创建的功能