I want to create binary images by upsampling a series of greyscale images (192 x 144 resolution) by a factor of 10 with the new pixel values being a pseudorandom distribution of 0's & 1's based on the original grey level value. The new resolution would be 1920 x 1440.
Here is a small example of a greyscale image:
i = Image[{{0.16, 0.22, 0.32}, {0.73, 0.06, 0.13}, {0., 0.86, 0.18}}, ImageSize->100]
The following function gives the desired result for such small images/arrays:
SeedRandom[123]
resize[dat_] :=
Map[SparseArray[
Partition[
RandomSample[
ConstantArray[0, IntegerPart[(1 - #)*100]]~Join~
ConstantArray[1, IntegerPart[100 #]]
], 10]] &, dat, {2}]
s = resize[ImageData@i];
bin = ArrayFlatten[s];
Image[bin, ImageSize -> 100]
However, when I try to uses it for a larger image ArrayFlatten gets upset...
SeedRandom[123]
bigi = Image@RandomReal[1, {50, 50}, WorkingPrecision -> 2]
ArrayFlatten[resize[ImageData@bigi]]
Obviously, I am stepping outside of ArrayFlatten's defined parameters, but I am unable to decipher the meaning of the error message...
Why is this happening?
Is there a simpler way to achieve my desired result for larger greyscale images?




resizehave the same dimension. – Henrik Schumacher Oct 11 '20 at 08:10SparseArrayshould be avoided here because the resulting arrays are not at all sparse. – Henrik Schumacher Oct 11 '20 at 11:43