I have set of image in one folder. How can I display random image from a folder when i click on a pushbutton?

 채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 20일

0 개 추천

%first you need to get the names of the images
projectdir = '/homes/users/hani/MATLAB/plan9/images'; %set as appropriate
img_exts = {'bmp', 'gif', 'jpg', 'png', 'tif'}; %list all the extensions you want to include
dinfo = [];
for K = 1 : length(img_exts)
dinfo = vertcat(dinfo, ...
dir( fullfile(projectdir, ['*.', img_exts{K}]) ) );
end
%now pick one randomly
randidx = randi( length(dinfo) );
randomfile = fullfile( projectdir, dinfo(randidx).name );
%read it
imagedata = imread(randomfile);
image(handles.TheDestinationAxes, imagedata); %display it
You will find it more efficient to create dinfo only once and store the data somewhere to be used when the button is pushed.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2015년 12월 20일

답변:

2015년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by