2017-08-14 46 views
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. 

如何解決這個問題?

回答

2

通常(並且這適用於其他編程語言),可以將圖像信號通常表示在2種方式:

  • 與強度值的範圍在[0, 255]。在這種情況下,這些值的類型爲uint8 - 無符號整數8字節。
  • 其強度值在[0, 1]的範圍內。在這種情況下,值是float

根據語言和庫的不同,像素強度允許的值的類型和範圍可以更寬容或更寬鬆。

在這裏的錯誤告訴你,像素你的形象價值(您arrayfloat類型,但它們是不在範圍[-1, 1]。由於值是[0, 255]之間,你只需要通過劃分他們都。255轉換值,以整數也可以從這個頁面工作

Here解釋是支持的圖像數據類型scikit圖像的用戶指南

兩句話:。

  • 需要注意的是浮動圖像應該被限制在-1到1即使數據類型本身可以超過這個範圍
  • 你不應該在圖像上使用astype,因爲它違反了有關的D型這些假設範圍
相關問題