Matlab code to split an image into a square grid of square blocks

15 ビュー (過去 30 日間)
Abigail Thomas
Abigail Thomas 2019 年 10 月 9 日
回答済み: Matt J 2019 年 10 月 10 日
Hello everyone,
I am having a hard time writing a matlab code that splits an image into a square grid of square blocks of side equal to where then shuffle the grid using randperm. So it is based on user input of how much the image should be cut down to, say the user inputs SplitImage(Image, r). All help is appreciated.
Capture.PNG

採用された回答

Matt J
Matt J 2019 年 10 月 10 日
This uses mat2tiles (Download)
A=mat2tiles( imread('cameraman.tif'), [32,32]);
[m,n]=size(A);
B=cell2mat(A(randperm(m), randperm(n)));
imshow(B)
untitled.png

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 10 月 9 日
See mat2cell() to do the splitting into cell arrays. Then randomize the cell array order, and then cell2mat() to restore.
You will have problems if your block size is not an exact divisor of the array size unless you take special care that all rows and columns in the randomized blocks add up to consistent sizes.
  1 件のコメント
Abigail Thomas
Abigail Thomas 2019 年 10 月 9 日
Thank you for you clear answer sir. Could you please supply with a code so I could compare mine with it? I am just starting out with Matlab.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by