How to read image data sets from a folder at once ?
이전 댓글 표시
Hello. I have 40 datasets in a folder in C drive. I need to convert those files from RGB to grayscale and should resize it but i am unable to read the file and cant convert all the files from RGB to gray at once and cant resize all the images at once and should save the converted and resized images. Can anyone help me with the coding of that please
채택된 답변
추가 답변 (1개)
KSSV
2017년 3월 26일
dinfo = dir('*.jpg');% image extension
for K = 1 : length(dinfo)
thisimage = dinfo(K).name; %just the name of the image
%read the image
%do something with the image
end
댓글 수: 20
Tousif Ahmed
2017년 3월 26일
KSSV
2017년 3월 26일
Why it will not read? Show the code and error.
Tousif Ahmed
2017년 3월 26일
편집: Jan
2017년 3월 26일
KSSV
2017년 3월 26일
What's the error it shall work...
Tousif Ahmed
2017년 3월 26일
KSSV
2017년 3월 26일
You copy the m file in the folder where your images are.
Jan
2017년 3월 26일
Perhaps you want:
folder = 'C:\Temp\'; % Set accordingly
dinfo = dir(fullfile(folder, '*.jpg'));
or with modern Matlab versions:
folder = 'C:\Temp\'; % Set accordingly
dinfo = dir(fullfile(folder, '**', '*.jpg'));
to include subfolders.
Tousif Ahmed
2017년 3월 26일
Then please explain the problem with more details. What exactly does "not working" mean? I do not understand this sentence:
The file is in C folder and there are 40 data sets each
with different folders but in the same folder from s01 to s40
Tousif Ahmed
2017년 3월 26일
Jan
2017년 3월 26일
I cannot guess what "data sets" mean and the description "from S01 to S40" does not help. Please remember that the readers do not have the faintest idea about what you are doing.
Is a "data set" a folder? What does "it is not working" mean explicitely? Perhaps you use an older Matlab version, which does not support searching recursively with the "\**\" method. But I cannot guess this.
Please give us a chance to help you by providing the details.
Tousif Ahmed
2017년 3월 26일
Tousif Ahmed
2017년 3월 26일
Tousif Ahmed
2017년 3월 26일
Jan
2017년 3월 26일
Okay. And when you use the method suggested by KSSV, what happens? Why does tis not satisfy you?
Tousif Ahmed
2017년 3월 26일
Jan
2017년 3월 26일
It is less useful if you only explain, what the code does not do. Better explain, what happens instead of your needs.
Start with reading the images:
dinfo = dir('*.jpg');% image extension
for K = 1 : length(dinfo)
thisimage = dinfo(K).name; %just the name of the image
%read the image
Img = imread(thisimage);
end
Does it work? If yes, insert some code to display the image. If no, please explain what happens instead.
Tousif Ahmed
2017년 3월 26일
I proceed with an own answer. Please read https://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099.
카테고리
도움말 센터 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!