I want to match the similarity of an image with all images of a folder. I compare the histogram error between to images using loop. But I've done some mistakes to code the loop. So, my program doesn't answer anything. The code is:
a = imread('c.jpg'); %read an image
srcFiles = dir('similar\*.jpg'); %directory of the source folder
Im1=rgb2gray(a); % convert images to type double (range from from 0 to 1 instead of from 0 to 255)
Im1 = im2double(Im1); % Calculate the Normalized Histogram
hn1 = imhist(Im1)./numel(Im1); for i = 1 : length(srcFiles) % determins how many images are there in the folder,
filename = strcat('similar\',srcFiles(i).name); Im2=rgb2gray(filename); Im2 = im2double(Im2); hn2 = imhist(Im2)./numel(Im2); % Calculate the histogram error
f(i) = sum((hn1 - hn2).^2);% Calculate the histogram errorf %display the result to console
end
Can anyone please help me to correct the mistakes???
Best Answer