How to convert my image data to idx3-ubyte?

조회 수: 14 (최근 30일)
MiMad
MiMad 2016년 7월 19일
편집: Willian Soares Girão 2017년 10월 14일
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
Willian Soares Girão
Willian Soares Girão 2017년 10월 14일
편집: Willian Soares Girão 2017년 10월 14일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by