After going through the N-Dimensional array convolution in Python found here on SO
I now face a problem around which I cannot wrap my head.
The convolution provided by from scipy.ndimage
does not allow to select the 'valid' part of the convolution like Matlab's convn
so we need to slice out the valid part.
"valid = [slice(kernel.shape[0]//2, -kernel.shape[0]//2), slice(kernel.shape[1]//2, -kernel.shape[1]//2)]"
With a kernel size of [2x2], I not sure as to why I do not get a valid slice for a convolution of image [24x24] with the kernel.
z = convolve(image,kernel)[valid]
In return I get a [22x22] image, where I was expecting a [23x23] image. I thus checked the values of the slice and it seems that -1 does not work here.
Doing a manual slice
convolve(image,kernel)[1:-1,1:-1] ---> Gives 22x22
convolve(image,kernel)[1:,1:] ---> Gives 23x23
So the question is... How come -1 gives the last item of a simple array but in my case of slicing it ignores it?
a= np.array([100,101,102])
a[-1]
102