MATLAB: How to compare images from 2 folders

compare imagesImage Processing Toolbox

Hello.I have 2 folders of images and want to compare each image in folder 1 with each image in folder 2 in order to find almost similar images. I wrote the code but it can not open images in for loop.can any one help me plz? Here is my code:
doc1 = dir('E:\fake1\*.jpg');
doc2 = dir('E:\fake2\*.jpg');
d_1 = size(doc1);
d_2 = size(doc2);
Inputs1 = {doc1.name}';
Inputs2 = {doc2.name}';
for I1 = 1:d_1;
for I2 = 1:d_2;
X_1 = imread([doc1 Inputs1{I1}]);
X_2 = imread([doc2 Inputs2{I2}]);
compare_images = imabsdiff(X_1,X_2);
figure;
imshow(compare_images);
title('compare_images');
%comp1 = imshowpair(X_1,X_2,'diff');
end
end

Best Answer

Fateme, this is in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F Look at the second code block.
Related Question