Effacer les filtres
Effacer les filtres

Matrix dimension conversion for image input layer

3 vues (au cours des 30 derniers jours)
Basu Sau
Basu Sau le 30 Mai 2021
Commenté : KALYAN ACHARJYA le 30 Mai 2021
Hi
I have been working on a machine learning task where I have stuck at a point where I need to manage size of matrices for next computations. I am quite unsure how to do it or is it possible to do it..
Currently, I have a matrix, A of size 1000 x 768. I am going to fed this data as an input to the image input layer to train a network. I found that image input layert accepts input in the dimension of [x y z].
I would like to convert the data of A to [1 21 768] size. Is it possible to do such reshaping?
I have tried one of the way like this:
[a,b]=size(A)
newA=reshape(A.', 1,1,a,b)
But it turns out that the data was converted to 1 x 1 x 768 format which I am not looking for.
What should be the ideal solution of this?
thanks,

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 30 Mai 2021
Modifié(e) : KALYAN ACHARJYA le 30 Mai 2021
Sir, you can convert the size of the image from 2D to 3D using the following way (The image isualization is not affected)
ori_image=imread('file_name'); %Original Gray Image
image_modied=cat(3,ori_image,ori_image,ori_image); % Image with rxcxslices
"Currently, I have a matrix, A of size 1000 x 768. I am going to fed this data as an input to the image input layer to train a network. I found that image input layert accepts input in the dimension of [x y z]."
%A in [x,y] format
modified_data=cat(3,A,A,A); % [x,y,z] format
  2 commentaires
Basu Sau
Basu Sau le 30 Mai 2021
Hi Kalyan
Thanks for your help. I have tried your suggestion and it reutrns 1000 x 768 x 3 size of matrix. But I have tried to manage the matrix A to 1 x 21 x 768 size. Is it possible or my idea needs to be reshaped?
KALYAN ACHARJYA
KALYAN ACHARJYA le 30 Mai 2021
If you want to change 1000 x 768 to 1 x 21 x 768 using reshape, here number of the elements must be same? Are the input features remain invariaent after the operation?
Have you checked on pen and paper?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by