how to read multiple pgm images ?
23 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
kitty varghese
il 17 Ago 2017
Commentato: Vipasha Sharma
il 23 Mag 2019
I'm working with a database which has 472 pgm files inside a folder named faces. I want to read all 472 and store it I
also each file inside the folder is name cmu_0000.pgm..........cmu_00471.pgm
4 Commenti
Stephen23
il 17 Ago 2017
@kitty Varghese: today I formatted your code correctly for you. In future you can do this yourself: simply select the code text and then click the {} Code button.
Stephen23
il 17 Ago 2017
@kitty Varghese: there is no point in getting dir to search for files with a .m extension:
thepath = ... *.m';
if what you are after is .pgm files. Do not hard-code how many files there are:
for i=1:472,
when it is much more robust to use numel. I would also recommend avoid i as a variable name.
Risposta accettata
Stephen23
il 17 Ago 2017
Modificato: Stephen23
il 17 Ago 2017
Something like this perhaps (untested):
P = 'C:\Users\kitty\Dropbox\non negative factorization\faces\face.test\test\face';
D = dir(fullfile(P,'*.pgm'));
C = cell(size(D));
for k = 1:numel(D)
C{k} = imread(fullfile(P,D(k).name));
end
Note I loaded that data into a cell array: this is because images commonly are stored as a 3D matrix: as an alternative you could store them is a 4D numeric array.
12 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!