MATLAB Answers

Matrix dimension conversion for image input layer

1 view (last 30 days)
Basu Sau
Basu Sau on 30 May 2021
Commented: KALYAN ACHARJYA on 30 May 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,

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 30 May 2021
Edited: KALYAN ACHARJYA on 30 May 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 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 30 May 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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!