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!