Loading specific Images from a folder
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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?
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.
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]).
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.
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)
