Vector2PictureMatrix.m 859 B

123456789101112131415161718192021222324252627282930
  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 = Vector2PictureMatrix(imgSz, N, Xset)
  19. Xmat = zeros(imgSz,imgSz, N,'uint8');
  20. for ii=1:N
  21. for jj=1:imgSz
  22. Xmat(jj,:,ii)=Xset((ii-1)*imgSz^2+(jj-1)*imgSz+1:(ii-1)*imgSz^2+jj*imgSz);
  23. end
  24. end
  25. end