1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your quick answer! I was aware of scipy.signals.convolve2d and its "boundary" parameter but I need to code it myself. I will use numpy.pad and if memory becomes a problem, I will handle the edges manually in my loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.