1

Given a image in form of 2D numpy array(etc, [H,W]), I want to slic several matrixes(etc, [N,N] N<H,W), which locate in different places of the image. Note that, to speed up, this operation should be parallel(This means that you cannot use a for loop to slic one by one as follows code).

for i in range(n): 
   matrix.append(image[y[i]:y[i]+matrix_h,x[i]:x[i]+matrix_w])
MaTiezheng
  • 23
  • 3
  • What have you tried? Stack Overflow doesn't write your code for you. – Frank Yellin Jan 11 '22 at 07:07
  • My current approach is to use a for loop, which slics matrix one by one. But this serial approach is very inefficient and I don't know if there is a more efficient parallel method. Moreover, I have update question with my code. – MaTiezheng Jan 11 '22 at 07:11
  • Is there any pattern in how you want to extract the image patches? Or are there just a bunch of independent patches? – Naphat Amundsen Jan 11 '22 at 07:22
  • 1
    The patches are independent and in a fixed size. Moreover, when slicing I already know the positions of all the patches. – MaTiezheng Jan 11 '22 at 07:25
  • @MaTiezheng I believe this answer fits your question: https://stackoverflow.com/questions/37901186/faster-way-to-extract-patches-from-images – Naphat Amundsen Jan 11 '22 at 07:42
  • 1
    @Naphat Amundsen Thank you very much! this is exactly what i need. – MaTiezheng Jan 11 '22 at 07:59

0 Answers0