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

采纳的回答

Walter Roberson
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 个评论
Snowleopard
Snowleopard 2016-8-1
编辑:Walter Roberson 2016-8-1
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by