How to convert my image data to idx3-ubyte?

18 views (last 30 days)
MiMad
MiMad on 19 Jul 2016
Hello,
l'm working with mnist dataset which has a format of idx3-ubyte. Now, l have created my own image dataset and l want to put them in the format of idx3-ubyte. How can l do that.
My images are formated as mnist 28*28 under the extension of png.
Thanks for your helps
  1 Comment
Willian Soares Girão
Willian Soares Girão on 14 Oct 2017
Edited: Willian Soares Girão on 14 Oct 2017
Hello there. I'm not exactly sure about the idx3-ubyte format but I guess that's only a matter of converting, lets say, the information stored as doubles to this format.
What I think that should be of any help to you is to first check the internal way that the original mnist dataset organizes the images. For example: I am currently working with mnist dataset used in PCANet. Internally the images are structured as vectors. So, for the train part of this dataset, the fisrt row of the matrix that holds all the training images is image1, the second row is image2, and so on, with each label appended at the end of the vectorized image.
I had to build my own dataset as well, so I had to preprocess then in order to have then with the same size, and then build a matrix with each vectorized image corresponding to a row in that matrix. Check the image below:
You can see that mnist_basic.mat has in the test dataset 50000 images, each one corresponding to a vector with 785 positions: the first 784 correspond to the image itself (28x28) and the last one is its label.
Heres a simple code to do that:
n_samples = 3;
data(1).im = imread('image1.png');
data(2).im = imread('image2.png');
data(3).im = imread('image3.png');
[w, d] = size(data(1).im);
data_train = zeros(n_samples, w*d);
for i = 1: n_samples
image = reshape(data(i).im, [1 w*d]);
im_aux_label = [image,lable]
data_train(i, :) = im_aux_label;
end
save('my_dataset.mat','data_train');
Hope it helps you somehow.

Sign in to comment.

Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!