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 件のコメント
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
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
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
2019 年 1 月 3 日
Are the images name are random in your case?
Yes you can do that, check here
Jack Zimmerman
2019 年 1 月 3 日
They have a theme:
Pos1 - People.jpg
Pos3 - People.jpg
Some entries are just missing.
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
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
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
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
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 件)
カテゴリ
ヘルプ センター および File Exchange で Blocked Images についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
