1
例如,我將對浮點數組應用均值過濾器,例如window_size=3
。我發現這個庫:爲什麼skimage平均過濾器不適用於浮點數組?
from skimage.filters.rank import mean
import numpy as np
x=np.array([[1,8,10],
[5,2,9],
[7,2,9],
[4,7,10],
[6,14,10]])
print(x)
print(mean(x, square(3)))
[[ 1 8 10]
[ 5 2 9]
[ 7 2 9]
[ 4 7 10]
[ 6 14 10]]
[[ 4 5 7]
[ 4 5 6]
[ 4 6 6]
[ 6 7 8]
[ 7 8 10]]
不過這個功能不能在浮標陣運行:
from skimage.filters.rank import mean
import numpy as np
x=np.array([[1,8,10],
[5,2,9],
[7,2,9],
[4,7,10],
[6,14,10]])
print(x)
print(mean(x.astype(float), square(3)))
File "/home/pd/RSEnv/lib/python3.5/site-packages/skimage/util/dtype.py", line 236, in convert
raise ValueError("Images of type float must be between -1 and 1.")
ValueError: Images of type float must be between -1 and 1.
如何解決這個問題?