フィルターのクリア

How do i randomly show the pictures i have in my array?

3 ビュー (過去 30 日間)
Glenn Macion
Glenn Macion 2015 年 3 月 19 日
編集済み: Glenn Macion 2015 年 3 月 24 日
this is my code:
folder = 'F:\school\matlab\project\pictures\pictures alone'
filePattern = fullfile(folder, 'apple.jpg','condor.jpg','elephant.jpg',...
'Koala.jpg','orange.jpg','whale.jpg','Penguins.jpg');
i would like to use imshow() to show the pictures but i want it to show random pictures from the filePattern i declared above... can anyone please help me with this?
i am using matlab R2013a

採用された回答

Guillaume
Guillaume 2015 年 3 月 19 日
Your usage of fullfile is incorrect. The arguments you pass except for the last should be folder.
There are many ways to do what you want. The gist of it is to store your options in a cell array and choose an element at random with any of the random functions, randi for example. Or just reorder the array with randperm.
folder = 'F:\school\matlab\project\pictures\pictures alone';
files = {'apple.jpg','condor.jpg','elephant.jpg',...
'Koala.jpg','orange.jpg','whale.jpg','Penguins.jpg'};
%pick one at random and show:
imshow(fullfile(folder, files{randi(numel(files))}));
pause(5)
%pick another at random, it may be the same
imshow(fullfile(folder, files{randi(numel(files))}));
%reorder the array randomly:
randomisedfiles = files(randperm(numel(files)));
%etc.
  3 件のコメント
Guillaume
Guillaume 2015 年 3 月 23 日
編集済み: Guillaume 2015 年 3 月 23 日
I'm not very clear on what you're asking. It sounds like you're after a method of tagging pictures and retrieving / searching these tags.
This is normally done with a database or some data structures that are not available in matlab (e.g. multi-index container). In matlab, what I would do is use a map.
If you wanted to make it easy to find images associated with a certain tag, the tags would be the keys, the images associated with the tag, the values, would be a cell array:
keys = {'fruits', 'animals', 'apples', 'birds'};
values = {{'apple.jpg', 'orange.jpg'}, {'condor.jpg', 'elephant.jpg', 'koala.jpg', 'whale.jpg', 'penguins.jpg'}, {'apple.jpg'}, {'condor.jpg', 'penguins.jpg}};
tagimages = containers.Map(keys, values);
%find images of birds:
birdimages = tagimages('birds')
%add a tag:
tagimages('Four legged') = {'elephant.jpg', 'koala.jpg'}
The issue with the above is that you duplicate the image strings a lot in the map (that can be worked around by storing indices to the cell array of filenames instead) and finding the tags associated with one image is not easy. Matlab unfortunately does not have a great deal of containers. To get something better, you'd have to use the database toolbox.
If what you want to do predominantly is find tags associated with an image, then you make the images the keys, and the tags the values:
keys = {'apple.jpg', 'orange.jpg', 'condor.jpg', 'elephant.jpg', 'koala.jpg', 'whale.jpg', 'penguins.jpg'};
values = {'fruit', 'apple'}, {'fruit'}, {'animal', 'bird'}, {'animal'}, {'animal'}, {'animal'}, {'animal', 'bird'}};
imagetags = containers.Map(keys, values);
appletags = imagetags('apple.jpg')
Glenn Macion
Glenn Macion 2015 年 3 月 24 日
編集済み: Glenn Macion 2015 年 3 月 24 日
thanks for your answer again... you have been very helpful...
i have another question ... i apologize if i sound very stupid about this... this is my first time trying programming... and i don't really learn fast by reading... but through the examples and answers you guys have given, i have been learning a lot so far... thank you... my other question is,... is there a way to not randomly show the pictures?
folder = 'F:\school\matlab\project\pictures\pictures alone'; files = {'apple.jpg','condor.jpg','elephant.jpg',... 'Koala.jpg','orange.jpg','whale.jpg','Penguins.jpg'};
%pick one at random and show: imshow(fullfile(folder, files{randi(numel(files))})); pause(5) %pick another at random, it may be the same imshow(fullfile(folder, files{randi(numel(files))}));
%reorder the array randomly: randomisedfiles = files(randperm(numel(files))); %etc.
like, what if i decide to show it according to how it has been sorted, respectively... i mean... from apple.jpg to Penguins.jpg... how do i use imshow(); to display it from the first row, first column to the last row and column of the array instead of doing it randomly..?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by