Random 1 image from folder and imread it
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, i have a problem with random 1 image from folder and imread it. In my current folder i have folder name "Test3" with 40 image, i would like random one and put in "image". I tried with this:
"MyImages = dir(fullfile('Test3','*.jpg'));
% generate a random number between 1 and the number of images
RandomNumber = randi([1 size(MyImages,1)]);
% get the corresponding name of the image
MyRandomImage = MyImages(RandomNumber).name;
% display the image
image=(imread(MyRandomImage));"
I got error:
"Error using imread>get_full_filename (line 568)
File "dog.4774.jpg" does not exist.
Error in imread (line 377)
fullname = get_full_filename(filename);
Error in zaajecia1>pushbutton16_Callback (line 587)
image=(imread(MyRandomImage));
"

0 件のコメント
回答 (1 件)
KALYAN ACHARJYA
2019 年 9 月 25 日
編集済み: KALYAN ACHARJYA
2019 年 9 月 25 日
Try?
%Save the folder of images in the current directory
path_directory='Test3'; % 'Folder name'
original_files=dir([path_directory '/*.jpg']);
filename=[path_directory '/' original_files(random(length(original_files))).name];
image_data=imread(filename);
Still the problem is not solved, then
% Save all images name in a sequence manner before doing the operation
% names for example im1,im2,im3...
Hope it helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!