Commit b1a63870 authored by Jesse Heckman's avatar Jesse Heckman
Browse files

mnistread

parent b585e07e
......@@ -37,7 +37,6 @@ function pb_vVORExp(varargin)
cd(cdir);
%% Vestibular blocks
BD = 60; % block duration in seconds
......
function images = pb_mnist2img(filename)
% PB_MNIST2IMG
%
% PB_MNIST2IMG(filename) reads all data in a mnist file and stores it in a
% image variable.
%
% See also FOPEN, FREAD
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
fp = fopen(filename, 'rb');
assert(fp ~= -1, ['Could not open ', filename, '']);
magic = fread(fp, 1, 'int32', 0, 'ieee-be');
assert(magic == 2051, ['Bad magic number in ', filename, '']);
numImages = fread(fp, 1, 'int32', 0, 'ieee-be');
numRows = fread(fp, 1, 'int32', 0, 'ieee-be');
numCols = fread(fp, 1, 'int32', 0, 'ieee-be');
images = fread(fp, inf, 'unsigned char');
images = reshape(images, numCols, numRows, numImages);
images = permute(images,[2 1 3]);
fclose(fp);
% Reshape to #pixels x #examples
images = reshape(images, size(images, 1) * size(images, 2), size(images, 3));
% Convert to double and rescale to [0,1]
images = double(images) / 255;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment