Reputation: 35
I am learning image convolution and in order to handle the edges, I want to repeat the first and last rows/columns of the original array (at the center) like this :
1 1 2 3 3
1 [1 2 3] 3
4 [4 5 6] 6
7 [7 8 9] 9
7 7 8 9 9
(The values in the corners correspond to the diagonal elements.)
I will iterate over each pixel of the original array and use the array above to extract its 3x3 neighbors. So here is my question: is it possible to generate the view corresponding to this array so that I don't need to store a new (n+2)x(m+2) array in memory?
Upvotes: 1
Views: 81
Reputation: 281663
There's no way to do this as a view, since there's no way to make the strides work. For a not-view solution, numpy.pad
does the job. The signal-processing routines you're using might also let you specify a padding type.
Upvotes: 1