i want a randomly scramble of a divided image into 4 blocks

4 ビュー (過去 30 日間)
Samaa Yasser
Samaa Yasser 2021 年 4 月 23 日
編集済み: Matt J 2021 年 4 月 23 日
please if i have image 256X256 and i divided it into 4 blocks, how can i scramble the blocks randomly or change the orders of the 4 blocks ,then i stitch them together again after this permutation or this changing inorder to change the parameters of the image and got a cihper one??
should i convert it to vector and then permuted or i can permuted it in blocks case?? please i want the code

回答 (2 件)

Matt J
Matt J 2021 年 4 月 23 日
編集済み: Matt J 2021 年 4 月 23 日
Using mat2tiles (which you must Download),
Image=imresize(imread('saturn.png'), [256,256]);
im=mat2tiles(Image,[128,128,inf]);
newImage=cell2mat( im(randperm(256/128), randperm(256/128)) );
subplot(1,2,1),imshow(Image);
subplot(1,2,2), imshow(newImage)

Jan
Jan 2021 年 4 月 23 日
編集済み: Jan 2021 年 4 月 23 日
img = uint8(((0:255) + (0:255).') / 2); % Test image
s = size(img);
% Split image to blocks:
img4 = reshape(img, s(1) / 2, 2, s(2) / 2, 2);
img4 = permute(img4, [1, 3, 2, 4]);
img4 = reshape(img4, s(1)/2, s(2)/2, 4);
% Mix:
img4 = img4(:, :, randperm(4));
% Get matrix again:
img4 = reshape(img4, s(1)/2, s(2)/2, 2, 2);
img4 = permute(img4, [1, 3, 2, 4]);
result = reshape(img4, s);
imagesc(result)
Or:
img = uint8(((0:255) + (0:255).') / 2); % Test image
s = size(img);
C = mat2cell(img, [s(1)/2, s(1)/2], [s(2)/2, s(2)/2]);
C(:) = C(randperm(4));
result = cell2mat(C);
imagesc(result)

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by