Compare one image to folder which have multiple images

1 次查看(过去 30 天)
I have a requirement to compare two images..
Input source an be either webcam/ image
compare source - a folder which has 15 images which is an extract from videos .
Code iam executing which i have picked from one FAQ source
% Specify the folder where the reference image file lives.
refFolder = 'C:\Users\Sneha\Desktop\MATLAB\video_extract'; % or wherever, such as 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(refFolder)
errorMessage = sprintf('Error: The following reference folder does not exist:\n%s', refFolder);
uiwait(warndlg(errorMessage));
return;
end
% Read in the reference image.
fullRefImageFileName = fullfile(refFolder, 'find_person2.jpg');
if ~exist(fullRefImageFileName, 'file')
errorMessage = sprintf('Error: The following reference image does not exist:\n%s', fullRefImageFileName);
uiwait(warndlg(errorMessage));
return;
else
refImage = imread(fullRefImageFileName);
end
% Specify the folder where the test image files live.
testFolder = 'C:\Users\Sneha\Desktop\MATLAB\video_extract\'; % or wherever, such as 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(testFolder)
errorMessage = sprintf('Error: The following test image folder does not exist:\n%s', testFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(testFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(testFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Read in test image.
testImage = imread(fullFileName);
imshow(testImage); % Display image.
drawnow; % Force display to update immediately.
% Now do whatever you want with this file name,
% such as comparing the image array with refImage in some function you write.
results = CompareImages(testImage, refImage);
end
results = CompareImages(testImage, refImage); --> This area getting an error
Unrecognized function or variable 'CompareImages'.
results = isequal(testImage, refImage); --> this is simply reading all images rather than comparing the tesimage(folder) and refimage(image given as imput source)

回答(1 个)

Image Analyst
Image Analyst 2022-5-15
Yes, we talked about this before. You need to write your own CompareImages function. It's not some generic function built in to MATLAB since there are thousands of ways to compare images. You'll just have to program up your own algorithm.
  7 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by