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
KALYAN ACHARJYA 2019 年 1 月 3 日
編集済み: KALYAN ACHARJYA 2019 年 1 月 3 日

0 投票

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 件のコメント

Jack Zimmerman
Jack Zimmerman 2019 年 1 月 3 日
編集済み: Jack Zimmerman 2019 年 1 月 3 日
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?
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 1 月 3 日
編集済み: KALYAN ACHARJYA 2019 年 1 月 3 日
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.
Jack Zimmerman
Jack Zimmerman 2019 年 1 月 3 日
編集済み: Jack Zimmerman 2019 年 1 月 3 日
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?
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 1 月 3 日
Are the images name are random in your case?
Yes you can do that, check here
Jack Zimmerman
Jack Zimmerman 2019 年 1 月 3 日
They have a theme:
Pos1 - People.jpg
Pos3 - People.jpg
Some entries are just missing.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 1 月 3 日
編集済み: KALYAN ACHARJYA 2019 年 1 月 3 日
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)?
Jack Zimmerman
Jack Zimmerman 2019 年 1 月 3 日
編集済み: Jack Zimmerman 2019 年 1 月 3 日
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]).
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 1 月 3 日
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.
Jack Zimmerman
Jack Zimmerman 2019 年 1 月 3 日
編集済み: Jack Zimmerman 2019 年 1 月 3 日
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.
Jack Zimmerman
Jack Zimmerman 2019 年 1 月 3 日
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by