How to randomize image display?

17 visualizaciones (últimos 30 días)
Jae
Jae el 9 de En. de 2013
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

Respuestas (3)

Image Analyst
Image Analyst el 9 de En. de 2013
Editada: Image Analyst el 9 de En. de 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

Jan
Jan el 9 de En. de 2013
Editada: Jan el 9 de En. de 2013
D = dir('.../matlab/BMP/*.bmp');
FileList = {D.name};
Index = randperm(length(a));
for ii = Index
img = imread(FileList{ii});
% what should happen with the image now?
image(img);
pause(0.5);
end

Thorsten
Thorsten el 9 de En. de 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

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by