# How to display an image pixel by pixel randomly

I want to display an image that each pixel appears randomly, the final result is an image without noise. I have tried this, but the result is not what I expected, How should I fix it?

img=ExampleData[{"TestImage","Lena"}];
data=ImageData[img];
{w,h}=ImageDimensions[img];
constArr=ConstantArray[N@{1,1,1},{h,w}];

Manipulate[constArr[[1;;i,1;;j]]=RandomSample@data[[1;;i,1;;j]];Image[constArr],{i,1,h,1},{j,1,w,1}]

• You can do many pixels at once with img = ExampleData[{"TestImage", "Lena"}]; dims = ImageDimensions[img]; rimg = RandomImage[1, dims]; Manipulate[ ImageAdd[Binarize[rimg, t], img] , {t, 0, 1}]. Note the final image is completely free of noise. But the problem with displaying it pixel-by-pixel is that there are 262144 frames in the animation because it's one frame for every pixel. I tried iteratively applying ReplacePixelValue on a shuffled list of pixel positions, but Mathematica is extremely slow. Oct 18, 2020 at 16:25
• Please consider a different example. Here's why: losinglena.com.
– JimB
Oct 18, 2020 at 19:34

Here is one of many possible approaches:

img = ExampleData[{"TestImage", "Mandrill"}];
data = ImageData[img];
{w, h} = ImageDimensions[img];

(* Total number of images *)
nImages = 100;

(* Random choice for which pixels are on or off for each image *)
r = Table[RandomVariate[BernoulliDistribution[i/(i + 1)], {w, h}], {i, nImages}];

(* All white for first image *)
r[[1]] = ConstantArray[0, {w, h}];

(* Full picture for last image *)
r[[nImages]] = ConstantArray[1, {w, h}];

(* Determine the pixels turned to white for each image so that pixels turned on
in one image stay on in the next *)
Do[r[[i]] = r[[i + 1]]*r[[i]], {i, nImages - 1, 2, -1}];

(* Create images *)
images = Table[Image[(r[[i]]*data) /. {0., 0., 0.} -> {1, 1, 1}], {i, 1, nImages}];

ListAnimate@images