How to read image data sets from a folder at once ?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
KSSV
el 26 de Mzo. de 2017
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 comentarios
Tousif Ahmed
el 26 de Mzo. de 2017
KSSV
el 26 de Mzo. de 2017
Why it will not read? Show the code and error.
Tousif Ahmed
el 26 de Mzo. de 2017
Editada: Jan
el 26 de Mzo. de 2017
KSSV
el 26 de Mzo. de 2017
What's the error it shall work...
Tousif Ahmed
el 26 de Mzo. de 2017
KSSV
el 26 de Mzo. de 2017
You copy the m file in the folder where your images are.
Jan
el 26 de Mzo. de 2017
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
el 26 de Mzo. de 2017
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
el 26 de Mzo. de 2017
Jan
el 26 de Mzo. de 2017
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
el 26 de Mzo. de 2017
Tousif Ahmed
el 26 de Mzo. de 2017
Tousif Ahmed
el 26 de Mzo. de 2017
Jan
el 26 de Mzo. de 2017
Okay. And when you use the method suggested by KSSV, what happens? Why does tis not satisfy you?
Tousif Ahmed
el 26 de Mzo. de 2017
Jan
el 26 de Mzo. de 2017
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
el 26 de Mzo. de 2017
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.
Categorías
Más información sobre Read, Write, and Modify Image en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!