converting vector to 3d array
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Salar
el 17 de Feb. de 2019
Respondida: Walter Roberson
el 17 de Feb. de 2019
I am working on CIFAR-10 dataset. I found that working with gray scale image would be easier for me at this time. The image are represented in a matrix. Each row of the matrix is one 32x32 RGB image. The first 1024 elements are red channel values. The next 1024 are green and finally the last 1024 are blue values. What I have in mind is converting the rows into 3D arrays then changing them from RGB to grayscale and finally saving them to a 4D array. Is there any efficient way for doing that? I mean without using for loops.
Thanks alot
0 comentarios
Respuesta aceptada
Walter Roberson
el 17 de Feb. de 2019
rgb2gray(reshape(TheVector, 32, 32, 3))
for any one vector of length 3072 (1024 x 1024 x 3). The result would be 2D, 32 x 32 . You could put a bunch of those together either along the third or fourth dimension, 32 x 32 x N or 32 x 32 x 1 x N.
Now, if you had a vector that was a multiple of 3072 long, representing different images, then it would start to get slightly interesting to do all of them at the same time without a loop.
temp = reshape(TheVector, 32, 32, 3, 1, []);
result = temp(:,:,1,1,:) * 0.299 + temp(:,:,2,1,:) * 0.587 + temp(:,:,3,1,:) * 0.114;
This would be 32 x 32 x 1 x N grayscale.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!