Created
April 14, 2012 16:00
-
-
Save Jim-Holmstroem/2385401 to your computer and use it in GitHub Desktop.
Parse filename and data in filecollection in matlab (in the example images)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [imgs]=LoadData(DirName) | |
imgs=dir(strcat(DirName,'/*.png')); | |
for it=1:numel(imgs) | |
%getting metadata from the filename itself | |
info=regexp(imgs(it).name,'(test|train)_digit(\d*)_(\d*)','tokens'); | |
info=info{1}; | |
if(numel(info)~=3) | |
error(strcat(imgs(it).name,' is malformed filename-format')); | |
end | |
imgs(it).istest=strcmp(info(1),'test'); | |
imgs(it).digit=info(2); | |
imgs(it).id=info(3); | |
%load the actual data | |
imgs(it).name=strcat(DirName,'/',imgs(it).name); %add folder | |
imgs(it).data=double(imread(imgs(it).name)); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment