How to read image data sets from a folder at once ?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tousif Ahmed
el 26 de Mzo. de 2017
Comentada: Tousif Ahmed
el 27 de Mzo. de 2017
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
0 comentarios
Respuesta aceptada
Jan
el 26 de Mzo. de 2017
Editada: Jan
el 27 de Mzo. de 2017
OutputFolder = 'C:\Temp'; % Set as needed [EDITED]
dinfo = dir('*.jpg');% image extension
for K = 1 : length(dinfo)
thisimage = dinfo(K).name;
Img = imread(thisimage);
Y = imshow(Img);
Gray = rgb2gray(Img);
GrayS = imresize(Gray, [112, 92], 'bilinear');
imwrite(GrayS, fullfile(OutputFolder, thisimage)); % [EDITED]
end
Or any other method for the resizing, see: doc imresize.
[EDITED] See the changed code for writing the changed file. Perhaps you want to modify the file name. Then you can split the file extension and the name by fileparts.
3 comentarios
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
Jan
el 26 de Mzo. de 2017
Editada: Jan
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.
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!