필터 지우기
필터 지우기

how to read multiple pgm images ?

조회 수: 25 (최근 30일)
kitty varghese
kitty varghese 2017년 8월 17일
댓글: Vipasha Sharma 2019년 5월 23일
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
Stephen23
Stephen23 2017년 8월 17일
@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
Stephen23 2017년 8월 17일
@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.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2017년 8월 17일
편집: Stephen23 2017년 8월 17일
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
kitty varghese
kitty varghese 2017년 8월 21일
편집: Walter Roberson 2017년 8월 21일
close all;
clear all;
clc;
% cbcldata - read face image data from cbcl database
% This is where the cbcl face images reside
P = 'C:\Users\kitty\Dropbox\non negative factorization\faces\face.test\test\face';
% Create the data matrix
D=dir(fullfile(P,'*.pgm'));
C=cell(size(D));
for k=1:numel(D)
C{k}=imread(fullfile(P,D(k).name));
col(:,k)=C(:);
V{k}=C(:);
end
this works perfectly .
Thanks @Stephen Cobeldick
Vipasha Sharma
Vipasha Sharma 2019년 5월 23일
can anyone help me with code for reading multiple HDF files?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by