Selecting One type of files from a folder,process and display the name

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 31 Jul 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 Comments
Snowleopard
Snowleopard on 1 Aug 2016
Edited: Walter Roberson on 1 Aug 2016
Thanks for your support,I have added below line to get only the name of file without ext.
[pathstr,name,ext]= fileparts(name_of_best)
disp(name)
It is displayed in command window. Now I want to display this name in static text box.I want to get this done without adding any push button i-e when above code runs it should display 'name' in static text box not anything else.
Alternatively, If possible to create a function to pick 'name' from the above code in static text, can I get help for this.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!