Not enough input arguments error while trying to change idx3 ubyte files to image files

3 次查看(过去 30 天)
Hello, I am trying to convert that file type into images. I have found some code from the internet to do that, but it doesn't work. t10kimages is the filename I want to translate. I found this code from here: https://github.com/davidstutz/matlab-mnist-two-layer-perceptron/blob/master/loadMNISTImages.m
I only changed the filenames into t10kimages, thinking that would fix it. I am kinda new to matlab, our teachers don't tell much and there isn't any good stuff on youtube about that, so don't be harsh please. I did some audio editing in matlab before but this is kinda hard for me.
function images = loadMNISTImages(t10kimages)
%loadMNISTImages returns a 28x28x[number of MNIST images] matrix containing
%the raw MNIST images
fp = fopen(t10kimages, 'rb');
assert(fp ~= -1, ['Could not open ', t10kimages, '']);
magic = fread(fp, 1, 'int32', 0, 'ieee-be');
assert(magic == 2051, ['Bad magic number in ', t10kimages, '']);
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
The error is this:
>> loadMNISTImages
Not enough input arguments.
Error in loadMNISTImages (line 5)
fp = fopen(t10kimages, 'rb');

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-3-24
编辑:Ameer Hamza 2020-3-24
You need to call the function loadMNISTImages with the name of the input file, as given below. Remember, you also need to download the four files containing the raw image data from here: https://github.com/davidstutz/matlab-mnist-two-layer-perceptron and put it in the same directory as the function loadMNISTImages. Also, remember to download the function loadMNISTLabels. The following code shows an example of how to call these functions.
images_test = loadMNISTImages('t10k-images.idx3-ubyte');
images_train = loadMNISTImages('train-images.idx3-ubyte');
labels_test = loadMNISTLabels('t10k-labels.idx1-ubyte');
labels_train = loadMNISTLabels('train-labels.idx1-ubyte');
% check some image
imshow(reshape(images_test(:,1), 28, [])); % first image in the test images
imshow(reshape(images_test(:,2), 28, []));
  2 个评论
Mahmut Dönmez
Mahmut Dönmez 2020-3-27
I used this code then it says this:
Attempt to execute SCRIPT loadMNISTImages as a function:
C:\Users\Emre\Documents\MATLAB\bolum3\loadMNISTImages.m
Error in loadMNISTImages (line 1)
images_test = loadMNISTImages('t10k-images.idx3-ubyte');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by