how to set threshold value for comparing images in matlab?
3 次查看(过去 30 天)
显示 更早的评论
how do I compare one image for example Z with multiple images in a folder and find out the one which matches closely to the image Z.
0 个评论
回答(2 个)
Image Analyst
2015-2-15
You develop an algorithm. That's about all I can say, given the (lack of) information you've provided. Please read this and provide more info.
4 个评论
Image Analyst
2015-2-16
Not that I'm aware of. You might be able to use a twain interface or java robot but I can't help you there.
Pranav Shukla
2023-3-28
编辑:DGM
2023-3-28
close all;
clc;
path='C:\Users\Vinayak Shukla\Documents\MATLAB\MATLAB PROJECTS\MASTER THESIS FOLDER 2023\happy15_encrpted4.bmp';
list=dir([path, '*.jpg']);
img=imread('C:\Users\Vinayak Shukla\Documents\MATLAB\MATLAB PROJECTS\MASTER THESIS FOLDER 2023\happy15_encrpted4.bmp');
%image to compare with X1=rgb2ind(img,16);
forx=1:length(list);
images{x}=imread([path, list(x).name]);
X2=rgb2ind(images{x},16);
c=corr2(X1,X2);
figure(x);
subplot(1,2,1),imshow(images{x}), xlabel(['Image ',num2str(x)]);
subplot(1,2,2),imshow(img);
if c==1
xlabel('The images are same.');
else
xlabel('The images are not same');
end
This is the error i am getting
Unrecognized function or variable 'x'.
Error in pranav17 (line 8)
images{x}=imread([path, list(x).name]);
6 个评论
Pranav Shukla
2023-3-30
编辑:DGM
2023-3-30
basepath = fullfile(matlabroot,'toolbox/images/imdata');
filenameexpr = '(C:\Users\Vinayak Shukla\Documents\MATLAB\MATLAB PROJECTS\MASTER THESIS FOLDER 2023\happy15_encrpted4.bmp)';
matchingfiles = dir(fullfile(basepath,filenameexpr));
Xref = imread(fullfile(matchingfiles().folder,matchingfiles().name));
numimages = numel(matchingfiles);
imagestack = cell(numimages,1); % preallocate
for k = 1:numimages
thispath = fullfile(matchingfiles(k).folder,matchingfiles(k).name);
Xtest = imread(thispath);
% store it if necessary
% if you don't need to keep them for later, don't bother
imagestack{k} = Xtest;
% test it somehow (corr2, immse, isequal)
c = immse(Xref,Xtest); % mean-square error
% generate a pile of figures
figure(k);
subplot(1,2,1),imshow(Xtest), xlabel(['Image ',num2str(k)]);
subplot(1,2,2),imshow(Xref);
if c==0 % if error is zero
xlabel('The images are same.');
else
xlabel('The images are not same');
end
end
>> pranav17
Error using fullfile
Not enough input arguments.
Error in pranav17 (line 26)
Xref = imread(fullfile(matchingfiles().folder,matchingfiles().name));
could some please rewrite the whole code again in a simplified manner, and post it here.
the code should be how to compare the threshold value of two images?
please help me out.
Image Analyst
2023-3-30
You have to give it an index of course. Is the reference your first image? If so,
Xref = imread(fullfile(matchingfiles(1).folder,matchingfiles(1).name));
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1340829/image.png)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!