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!