How to randomize image display?
17 views (last 30 days)
Show older comments
Hello,
I was trying to load images from a folder and display them randomly. I did my best to write the codes but when I run the program it only prints "166" on the screen for non-stop 5 minutes. This is my first programming and I need your help.
The function code I wrote for loading images was: I appreciate any comments. Thank you.
function words = words_load(N)
D=dir('.../matlab/BMP/*.bmp');
a={D.name};
b=numel(a);
c=[randperm(b)];
for i=1:b
filenumber=c(:,b)
file=sprintf('w_%02d.bmp',filenumber)
img=imread(file)
end
0 Comments
Answers (3)
Image Analyst
on 9 Jan 2013
Edited: Image Analyst
on 9 Jan 2013
Try it like this instead:
allFiles = dir('*.bmp');
baseFileNames = {allFiles.name}
numberOfFiles = length(baseFileNames)
randomOrder=[randperm(numberOfFiles)]
for k = 1 : numberOfFiles
filenumber = randomOrder(k)
fullFileName = fullfile(pwd, baseFileNames{filenumber})
% Display the image in the current axes.
% img = imread(fullFileName)
% imshow(img);
% Prompt user to continue or quit.
message = sprintf('Now showing %s', fullFileName);
promptMessage = sprintf('%s\nDo you want to Continue processing,\nor Cancel to abort processing?', message);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
break;
end
end
0 Comments
Thorsten
on 9 Jan 2013
myimagedir = '.../matlab/BMP/*.bmp';
d = dir(myimagedir);
for i = randperm(numel(d)) % show all images in random order
imshow(d(i).name)
pause(2) % wait for 2 s until the next image is shown
end
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!