Equivalent Matlab imfilter function in Python

I know that equivalent functions conv2and corr2MATLAB are scipy.signal.correlateand scipy.signal.convolve. But a function imfilterhas the property of dealing with the outer boundary of an array. Like symmetric, replicateand circular. Can Python do this.

+4
source share
2 answers

Using functions scipy.ndimage.filters.correlateandscipy.ndimage.filters.convolve

+1
source

To add solid code, I needed the equivalent imfilter(A, B)in python for a simple two-dimensional image and filter (kernel). I found that the following gives the same result as MATLAB:

import scipy.ndimage
import numpy as np
scipy.ndimage.correlate(A, B, mode='constant').transpose()

For this question, this will work:

scipy.ndimage.correlate(A, B, mode='replicate').transpose()

, - MATLAB .

. .

1:

MATLAB , . , 'conv', MATLAB ():

imfilter(x, f, 'replicate', 'conv')

:

scipy.ndimage.convolve(x, f, mode='nearest')

, 'replicate' MATLAB 'nearest' SciPy python.

+2

Source: https://habr.com/ru/post/1529759/


All Articles