What is the mistale in the loop?
Ältere Kommentare anzeigen
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???
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 16 Mär. 2014
0 Stimmen
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/
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!