Selecting One type of files from a folder,process and display the name
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Snowleopard
il 31 Lug 2016
Commentato: Walter Roberson
il 1 Ago 2016
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 Commenti
Risposta accettata
Walter Roberson
il 31 Lug 2016
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 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!