图像中像素的随机排列

Random arrangement of pixel in image

我需要随机重新排列一幅图像中像素的位置,但像素值不会改变。可以给我一些想法,我将如何解决这个问题吗?

使用randperm

img = imread( ... ); % read image
rimg = reshape( img, [], size(img,3) ); % arrange as 1D image with x-channels
n = size(rimg,1); % how many pixels you have
simg = rimg( randperm(n), : ); % shuffle pixels
simg = reshape( simg, size(img) ); % reshape back