Not enough input arguments error while trying to change idx3 ubyte files to image files
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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');
0 comentarios
Respuestas (1)
Ameer Hamza
el 24 de Mzo. de 2020
Editada: Ameer Hamza
el 24 de Mzo. de 2020
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 comentarios
Ameer Hamza
el 27 de Mzo. de 2020
Is C:\Users\Emre\Documents\MATLAB\bolum3 you current folder in MATLAB?
can you paste the output of
type loadMNISTImages
Ver también
Categorías
Más información sobre Get Started with Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!