Loading specific Images from a folder
显示 更早的评论
I have a folder of images, I would like to extract it as it appears in an array of my choosing.
E.G I have an array: [1 2 3];
This would extract the name of the first 3 images in this order.
E.G [1 2 3 5];
This would extract the name of the first 3 images and the 5th image also in this order.
I would like these Imagenames to be presented in a folder.
Is there a way to do this?
采纳的回答
KALYAN ACHARJYA
2019-1-3
编辑:KALYAN ACHARJYA
2019-1-3
path_directory='ddb1_fundusimages'; % 'Folder name'
original_files=dir([path_directory '/*.png']);
array1=[5 10 15];
j=1;
for k=1:length(array1)
filename=[path_directory '/' original_files(array1(j)).name];
j=j+1;
image1=imread(filename);
figure, imshow(image1);
% Do the Image Operation as per your work
end
Before doing the above operations , please ensure the all images are sorted in namewise.
(For reference see the attach image)

10 个评论
When placing the images in my folder through matlab, a few URL's threw errors, as a result they were skipped. Therefore, the folder does not have a perfect sequence.
Could your code be based on the exact order it was read from the folder. As in the array [1 2] represents the first and second image read from the folder. Which may be the Image001 and Image003.
How I preserve the order in my folder?
Save the images in namewise im1, im2, im3..etc, code take images based on array order sequence.
The code os perfectly working in my case.
Doesnt work for my intended use yet.
Is there a way then to take those images and save them as 1,2,3 ect... while preserving the order they are in now?
Or must it be a manual process?
Are the images name are random in your case?
Yes you can do that, check here
They have a theme:
Pos1 - People.jpg
Pos3 - People.jpg
Some entries are just missing.
Can you share the some 10 (sequence from starting) images, so that I can try on it?
use google drive
Please confirm-you want to call the images from folder as per array indexing values (not random)?
Ive used certain images from that folder, perhaps the 1st,3rd and 5th. I want to call the names of these images and save them in a cell perhaps.
E.G Ive used the 1st,3rd and 5th Images
Their names are:
Image001.jpg, Image004.jpg and Image007.jpg respectively, I would like to save the names of these images in a cell on matlab presented like this perhaps:
'Image001.jpg' (1st Image)
'Image004.jpg' (3rd Image)
'Image007.jpg' (5th Image)
However I would like to do so, by referrencing their order within the folder so i dont have to manually check for their names, hence, the array ([1 3 5]).
Do the first part, then think on sencond task (save in a cell). It is OK in my case. Whi I have run the above code, from my database it call the 5th image, 10th image and 15th image.
If the images number are less do the renaming and apply the code.
When the files are saved in "origional_files" using dir, their ordering becomes changed.
From:
Pos1 - People.jpg, Pos2 - People.jpg, Pos3 - People.jpg
To:
Pos1 - People.jpg, Pos100 - People.jpg, Pos1000 - People.jpg
Thus the images are not provided in order and the iterating doesnt work.
Ive managed to find the resources to do this, here is the code:
path_directory='People'; % 'Folder name'
original_files=dir([path_directory '\*.jpg']);
Ordered = {original_files.name};
Ordered=natsortfiles(Ordered);
ImagesRequired = {};
for i = k'
ImagesRequired{i} = Ordered{i};
end
ImagesRequired = ImagesRequired';
ImagesRequired(cellfun('isempty', ImagesRequired)) = [];
The function natsortfiles(), is user generated from this link:
This provides the exact format I was looking for.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Blocked Images 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
