-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_face_images.m
executable file
·64 lines (48 loc) · 1.68 KB
/
load_face_images.m
1
function [image_stack, scriptV] = load_face_images(image_dir)% LOAD_FACE_IMAGES Load the set of face images. % image_dir: path to the image directory%% image_stack: all images stacked along the 3rd channel% scriptV: light directions%% Source: Marc Pollefeys, 2006num_images = 64;% get ambient imagefilename = [image_dir 'yaleB02_P00_Ambient.pgm'];ambient_image = getpgmraw(filename);[h, w] = size(ambient_image);% get list of all other image filesd = dir([image_dir 'yaleB02_P00A*.pgm']);% randomly select num_images number of imagesfilenames = {d(:).name};total_images = numel(filenames);if num_images <= total_images filenames = {d(randperm(numel(d), num_images)).name};else fprintf('Total available images is less than specified.\nProceeding with %d images.\n', total_images)endNimages = numel(filenames);% arrays to store the angles of light sourcesAng = zeros(2, Nimages);% create array of illuminated imagesimage_stack = zeros(h, w, Nimages);for j = 1 : Nimages m = strfind(filenames{j},'A')+1; Ang(1,j) = str2double(filenames{j}(m:(m+3))); m = strfind(filenames{j},'E')+1; Ang(2,j) = str2double(filenames{j}(m:(m+2))); image_stack(:,:,j) = getpgmraw([image_dir filenames{j}]);end[X,Y,Z]= sph2cart(pi*Ang(1,:)/180,pi*Ang(2,:)/180,1);scriptV = [Y;Z;X];scriptV = scriptV';%% preprocess the data: % subtract ambient_image from each image in imarrayimage_stack = bsxfun(@minus, image_stack, ambient_image);% make sure no pixel is less than zeroimage_stack(image_stack < 0) = 0;% rescale values in imarray to be between 0 and 1minVal = min(image_stack(:));maxVal = max(image_stack(:));image_stack = (image_stack - minVal) / (maxVal - minVal);end