[Python] Difference between convolve2d and filter2D. Why is there a difference in output...

Discussão em 'Python' iniciado por Stack, Agosto 7, 2025.

  1. Stack

    Stack Membro Participativo

    I need to perform a 2D convolution. I have a similarity matrix of shape 100, 100 and a filter of shape 5,5.

    If I do using scipy:

    scipy.signal.convolve2d(similarity_matrix, np.diag(filter))


    I get 104,104 matrix in response.

    But if I do using OpenCV's filter2D method:

    cv2.filter2D(similarity_matrix, -1, np.diag(filter))


    I get a 100,100 matrix in response.

    • What is happening here? Why is there a difference in shape?
    • With convolve2d why do I get 4 extra rows and 4 extra columns?

    Continue reading...

Compartilhe esta Página