Vector2Matrix.m 818 B

12345678910111213141516171819202122232425262728
  1. %% Vector to 3D Matrix containing N images
  2. % The function provides convertion from a Vector containing N grayscale
  3. % [0, 255] layers pictures of square size ImgSz*ImgSz [px] in a 3D Matrix
  4. % containing N layers, each one of them will contain a single picture.
  5. %
  6. % Inputs:
  7. % - imgSz Size of the single squared picture
  8. % - N Total Number of pictures
  9. % - Xset Input Vector
  10. %
  11. % Outputs:
  12. % - Xmat 3D Matrix containing the pictures
  13. %%
  14. %% Filling the Matrix
  15. % The for cycles loop over the Vector Xset: the outer cycle runs over the N pictures,
  16. % the inner cycle copies a row of each picture to the current one.
  17. %%
  18. function Xmat = Vector2Matrix(imgSz, N, Xset)
  19. imgSzSq=imgSz^2;
  20. Xmat = zeros(imgSz*imgSz, N,'uint8');
  21. for jj=1:N
  22. Xmat(:,jj)=Xset(imgSzSq*(jj-1)+1:imgSzSq*jj);
  23. end
  24. end