Selecting One type of files from a folder,process and display the name
1 次查看(过去 30 天)
显示 更早的评论
I have a folder with unknown 'n' number of image files. I want to correlate all of these images with a 'single image'obtained from another location.The name of the image from 'n' image files which has highest correlation coefficient with 'single image', should be displayed as answer. following link is very helpful but can I need to run a loop to correlate 'single image' with 'n'files from the folder and display the name, can I get help in this, thanks in advance
0 个评论
采纳的回答
Walter Roberson
2016-7-31
projectdir = 'NameOfDirectoryWithMultipleImages';
dinfo = dir(projectdir);
dinfo([dinfo.isdir]) = []; %get rid of subdirectories and . and .. from directory list
n = length(dinfo);
best_corr = -inf;
best_corr_idx = 0;
name_of_best = '';
for K = 1 : n
this_file = fullfile(projectdir, dinfo(K).name);
try
this_image = imread(this_file);
correlation_score = correlate_two_images(this_image, the_single_image);
if correlation_score > best_corr
best_corr = correlation_score;
best_corr_idx = K;
name_of_best = dinfo(K).name;
end
catch
fprintf('could not read file as image file: "%s"\n', this_file);
end
end
if best_corr_idx == 0
fprintf('There were no usable image files in directory "%s"\n', projectdir);
else
fprintf('The best correlation was with the image "%s"\n', name_of_best);
end
2 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!