split image and create a new one using this pieces

9 vues (au cours des 30 derniers jours)
Sergio José Uc Magaña
Sergio José Uc Magaña le 2 Mai 2022
Commenté : Jon le 3 Mai 2022
how can I split an image into N parts and create a new one mixing this pieces. Example:
Take and CT image of 128x128, split it in 16 parts of 32x32 and create a new artificial CT image mixing this pieces.

Réponses (1)

Jon
Jon le 2 Mai 2022
Does this do what you want:
% make an example image
A = randi(128,128);
% chop it up into 32 x 32 squares
B = reshape(A,32,32,16);
% rearrange the squares
C = B(:,:,randperm(16));
% put them back together as an image
C = reshape(C,128,128);
  11 commentaires
Walter Roberson
Walter Roberson le 3 Mai 2022
reshape(32,32,16) does not mean that 32 by 32 squares should be chopped out of the array. It means that the first 1024 (32*32) elements in memory should be put into the first plane, the next 1024 into the second plane, and so on. With you having resized to 128 x 128, the first 1024 entries in memory are the first 8 rows.
Use mat2cell to break up into tiles, or there is a File Exchange contribution... im2tiles or some name like that.
Jon
Jon le 3 Mai 2022
Thanks @Walter Roberson. I'm really sorry, for sending you down the wrong path on this. I didn't really think this through. As Walter explains, the reshaping will take the values columnwise out of the original array, not what you wanted.

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