How to randomize image display?
17 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (3 件)
Image Analyst
2013 年 1 月 9 日
編集済み: Image Analyst
2013 年 1 月 9 日
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 件のコメント
Thorsten
2013 年 1 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!