How to import the images into 2D array (one image per row)?

조회 수: 1 (최근 30일)
May
May 2017년 2월 18일
댓글: May 2017년 2월 19일
I downloaded the DeepLearnToolbox-master and try to train the CNN. In the test_example_CNN.m,the train images are imported into 2D matrices (one image per row). I would like to train the CNN with my own images, but I don't know how to import the images into 2D array (one image per row). Please, explain me how to do it.
Thanks, May
% Load the MNIST hand-written digit dataset.
load mnist_uint8;
% Reshape the example digits back into 2D images.
%
% 'train_x' and 'test_x' begin as 2D matrices with one image per row.
% train_x [60000 x 784]
% test_x [10000 x 784]
%
% Also, rescale the pixel values from 0 - 255 to 0 - 1.
train_x = double(reshape(train_x',28,28,60000))/255;
test_x = double(reshape(test_x',28,28,10000))/255;
train_y = double(train_y');
test_y = double(test_y');
% You can use this command to display an example image. Note that the
% images need to be transposed in order to be oriented properly.
colormap gray;
imagesc(train_x(:, :, 105)');
axis square;

채택된 답변

Walter Roberson
Walter Roberson 2017년 2월 18일
img = imread(TheFileName);
train_x(end+1,:) = reshape(img, 1, []);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by