Hello, I want to extract n_sample 3D patches with shape is 32x32x32 (i.e n_sample=1000) from a 3D input (such as 256x128x256). I found that view_as_windows as a candidated solution. However, it does not support the random extraction. How could I use the function (or another function) to implement my work? Thanks all
@John1231983 why don't just sample the hypercube origin coordinates via numpy.random.randint and use them for slicing?
I.e. (pseudocode, not tested):
from numpy.random import randint
origin_row = randint(0, 255-32, n_sample)
origin_col = randint(0, 127-32, n_sample)
origin_dep = randint(0, 255-32, n_sample)
for o_r, o_c, o_d in zip(origin_row, origin_col, origin_dep):
do_something(arr[o_r:o_r+32, o_c:o_c+32, o_d:o_d+32])
P.S. Please, consider using StackOverflow for posting general questions.
In addition to the StackOverflow option, you can also try the mailing list, [email protected]. Thanks for your interest @John1231983!
@John1231983 have you created 3D patch from input, can you share your code about creating patches.
@saqibqamar here is one: https://github.com/konopczynski/Vessel3DDL/blob/master/scripts/utils/patches_3d.py
Most helpful comment
@John1231983 why don't just sample the hypercube origin coordinates via
numpy.random.randintand use them for slicing?I.e. (pseudocode, not tested):
P.S. Please, consider using StackOverflow for posting general questions.