in a nutshell: I need a fast(precompiled) function like filter2d from OpenCV with double type output. Not integer.
Detail: I have numpy array which store the monochrome image from OpenCV.
I need to calculate the mean values of matrix for some square (for example) kernel like this:
kernel size = (3,3)
input array:
[[13 10 10 10]
[12 10 10 8]
[ 9 9 9 9]
[ 9 10 10 9]]
output array:
[[ 10.22222222 9.44444444]
[ 9.77777778 9.33333333]]
For example: 10.22222 = (13+10+10+12+10+10+9+9+9)/9
I write this function:
def smooth_filt(src,area_x,area_y):
y,x = src.shape
x_lim = int(area_x/2)
y_lim = int(area_y/2)
result = np.zeros((y-2*y_lim,x-2*x_lim), dtype=np.float64)
for x_i in range(x_lim,x-x_lim):
for y_i in range(y_lim,y-y_lim):
result[y_i-y_lim, x_i-x_lim] = np.mean(src[y_i-y_lim:y_i+area_y-y_lim,x_i-x_lim:x_i+area_x-x_lim])
return result
But this is not fast enough.
Please tell me if there is a faster way to calculate this.
Answer: I check all methods. You can see the code: http://pastebin.com/y5dEVbzX
And decide that blur is most powerful method it is almost independent on kernel size.
The graph of one image processing with different methods. testing set is 298 images.