How to read image data sets from a folder at once ?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tousif Ahmed
am 26 Mär. 2017
Kommentiert: Tousif Ahmed
am 27 Mär. 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 Kommentare
Akzeptierte Antwort
Jan
am 26 Mär. 2017
Bearbeitet: Jan
am 27 Mär. 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 Kommentare
Weitere Antworten (1)
KSSV
am 26 Mär. 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 Kommentare
Jan
am 26 Mär. 2017
Bearbeitet: Jan
am 26 Mär. 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.
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!