[PYTHON] About scipy Gaussian filter

scipy.ndimage.gaussian_filter [reference]

usage.py


from scipy.ndimage import gaussian_filter
blur_array = gaussian_filter(input, sigma)

As of v1.5.4, the arguments look like this.

argument Explanation Default
input It is OK if it is in array format. Mandatory
sigma Standard deviation of Gaussian distribution, degree of blurring. Can be set for each axis.
(Example)In 3D sigma=[3,6,9]
Mandatory
order Derivative rank, if it is 1 or more, order the filter. Can be set for each axis. 0
output Output data format. Same as input
mode Behavior when applying a filter at the edge, described later.
(type) ‘reflect’ ``‘constant’``‘nearest’ ``‘mirror’``‘wrap’
‘reflect’
cval A value outside the input array. mode=Applicable when ‘constant’. 0.0
truncate The scope of application of the filter. Filter radius=int(sigma*truncate+0.5) 4.0

About sigma

・ Scalar values ​​are the same for all axes $ \ sigma $. ・ If it is a sequence (number of elements = input dimension), $ \ sigma $ is specified for each axis.

Result example

Color image
Color smoothing
Color image Grayscale image Smoothing only in the X direction Smoothing only in the Y direction

About mode

-How to handle values ​​outside the edge (edge ​​of the array). ・ The default is ‘reflect’ -The behavior when the input sequence is abcd is described in the table.

mode= Explanation Out of array left Input array Out of array right
‘reflect’ Reflected around the edge.(Edges are also reflected) d c b a a b c d d c b a
‘constant’ constantcval, Default is 0 k k k k a b c d k k k k
‘nearest’ The value of the closest edge. a a a a a b c d d d d d
‘mirror’ Reflected around the edge.(Edges do not reflect) d c b a b c d c b a
‘wrap’ Wrap around the opposite edge a b c d a b c d a b c d

About truncate

・ Smoothing range ・ Default is 4 -If you check the code, probably the filter radius = int (sigma * truncate + 0.5) [code]

Result example

If truncate is 4 or more, there is almost no difference, so there seems to be no need to mess with it. mandrill.gif

Recommended Posts

About scipy Gaussian filter
Create filter with scipy
About django custom filter arguments
Image processing with Python 100 knocks # 9 Gaussian filter