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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentare
Snowleopard
Snowleopard am 1 Aug. 2016
Bearbeitet: Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by