mhk777
mhk777

Reputation: 93

scipy.signal.convolve flips axis in result when using 'same'

I'm using scipy.signal.convolve to apply a simple filter to a grayscale picture My inputs are as follows:
kk -> filer (2x2)
im -> image (500x800) opened via pillow

>>> from scipy.signal import convolve as cv
>>> kk
[[1, 2], [1, 2]]
>>> im.size
(500, 800)
>>> cvRes = cv(im,kk,'same')

When I apply the convolution, I was expecting the result to be in a shape of (500,800), i.e. same as the input image (im), but the results are in shape of (800,500).

>>> cvRes = cv(im,kk,'same')
>>> cvRes.shape
(800, 500)

I'm a bit confused regarding this output, I think I maybe missing something or misunderstanding how the library is supposed to work.
Appreciate any help in regards to how to get a non flipped output and if I can just flip the x/y when trying to get the value of single pixel?

Thanks!

Upvotes: 0

Views: 490

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54698

This is a side effect of PIL. A PIL image with size (800,500) has 500 rows of 800 columns. When that becomes a numpy array, it has a shape of (500,800). So, it's not that the array is being transposed, it's that the two modules number the axes differently.

Upvotes: 1

Related Questions