Newer
Older
SparseCodingDynamicOcclusions / MatLab-Code / loadImages.m
@Hvitgar Hvitgar on 22 Sep 2016 719 bytes Code, Data and Thesis added
function [C, names] = loadImages(dirPath, fileType)
% load images from a folder
poolobj = gcp('nocreate'); % If no pool, do not create new one.
poolcreated = false;
if isempty(poolobj)
    poolobj = parpool;
    poolcreated=true;
end

contents = dir([dirPath fileType]);
if length(contents) < 1
   error('No Images found in specified folder'); 
end

names = {contents.name};

firstIm = imread([dirPath contents(1).name]);

[m, n] = size(firstIm);
C=zeros(length(contents), m, n);

parfor idx = 1:length(contents)
    C(idx, :, :) = imread([dirPath contents(idx).name]);
end

disp('Loading completed');

% if this function created a pool object, it will be deleted after use
if(poolcreated)
    delete(poolobj);
end

end