Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the python equivalent for Matlab's stdfilt() function?

Tags:

python-2.7

I was trying to convert a piece of code in Matlab to python. There I could find a Standard deviation filter function "stdfilt()" for which I could not find any equivalent API in python. The Matlab code is given below,

Ig_med = medfilt2(Input_Image);
h_gauss = fspecial('gaussian',11,2);
h_avg = fspecial('average',121);
I = imfilter(Ig_med,h_gauss,'corr','replicate');

P = stdfilt(I,ones(121));
P = P.^2; 

Q = imfilter(P,h_avg,'corr','replicate');

Can anyone help me out in implementing the above piece of code in Python ?

Thanks in Advance

like image 666
Kevin Karl Avatar asked Oct 22 '13 13:10

Kevin Karl


1 Answers

I found something on

https://nickc1.github.io/python,/matlab/2016/05/17/Standard-Deviation-(Filters)-in-Matlab-and-Python.html

from scipy.ndimage.filters import generic_filter
import numpy as np

I_filt = generic_filter(I, np.std, size=3)

maybe it can help! (not you I guess, given the 3 years delay, but someone on the net)

like image 85
david Avatar answered Oct 08 '22 18:10

david