What is the mistale in the loop?
Show older comments
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 error
f %display the result to console
end
Can anyone please help me to correct the mistakes???
Accepted Answer
More Answers (1)
Image Analyst
on 16 Mar 2014
0 votes
What is length(srcFiles)? It sounds like it's not even entering the loop since you said it doesn't do anything at all. Did you step through the code? http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!