How to get random image from specific folder in matlab ?

I have set of image in one folder. From that I want to get only one image from this folder. You can get one image by any feature or any logic or non logic..

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 4 Mai 2014
Modifié(e) : Azzi Abdelmalek le 4 Mai 2014
d='Yourfolder';
f=dir([d '\*.jpg']);
n=numel(f);
idx=randi(n);
im=imread(f(idx).name);
imshow(im)

2 commentaires

I am using Matlab 2012 and got this type of error.. Thanks for your reply...
Error using randi First input must be a positive scalar integer value IMAX, or two integer values [IMIN IMAX] with IMIN less than or equal to IMAX.
Error in One_image (line 11) idx=randi(n);
Azzi Abdelmalek
Azzi Abdelmalek le 4 Mai 2014
Modifié(e) : Azzi Abdelmalek le 4 Mai 2014
This is because your folder is empty, I mean it doesn't contain jpg files

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by