While reading the paper Local Shannon entropy measure with statistical tests for image randomness, I come up with the following question:
Given an input image X of size mn, a block size of T, generate k random non-overlapping blocks of size TT.
I came up with the idea that represent every block by its top-left coordinate. Then, I used the following piece of code to generate those non-overlapping blocks. Although I employed some randomness into this code, the result is not random and does not cover all possible situations. Are there any efficient algorithms for doing this? Even keywords for further search are appreciated.
m, n = Y.shape
T = 44
k = 30
possible_blocks_vert = m // T
possible_blocks_horiz = n // T
possible_blocks = possible_blocks_vert * possible_blocks_horiz
if possible_blocks < k:
assert False
else:
last_possible_starting = (divmod(m, T)[1], divmod(n, T)[1])
random_y0, random_x0 = np.random.randint(last_possible_starting[0]), np.random.randint(last_possible_starting[1])
random_xs = [random_x0+i*T for i in range(possible_blocks_horiz)]
random_ys = [random_y0+i*T for i in range(possible_blocks_vert)]
i = 0
Xs = []
Ys = []
for x in np.random.permutation(random_xs):
for y in np.random.permutation(random_ys):
Xs.append(x)
Ys.append(y)
i += 1
if (i >= k):
break
if (i >= k):
break
Xs, Ys
There are at least two downsides to this implementation:
- The selection first selects all of the first random row, then all of the second and so on until all k blocks are chosen
- The selection is not distributed in all possible places.
Note. The paper proposes a novel measure called Local Shannon Entropy, LSE, which generates k random blocks and compute their average Shannon entropy as LSE.