1
我嘗試拍攝Image PixelRGB8並將其轉換爲矩陣,以在矩陣上進行一些卷積運算。對於第一次嘗試,我想將其轉換爲矩陣並將矩陣轉換回圖像。Haskell,將圖像轉換爲矩陣
我收到此錯誤:
• No instance for (Element Word8)
arising from a use of ‘matrixToImg’
• In the expression: matrixToImg $ imgToMatrix img
In an equation for ‘convImg’:
convImg img = matrixToImg $ imgToMatrix img
Failed, modules loaded: none.
這是什麼意思?
這是代碼。
import Codec.Picture
import Data.Matrix
import Data.Vector
import Data.Vector.Storable
import Debug.Trace
import GHC.Word
import Numeric.LinearAlgebra.Data
import Numeric.LinearAlgebra
convImg ::Image PixelRGB8 -> Image PixelRGB8
convImg img = matrixToImg $ imgToMatrix img
imgToMatrix ::Image PixelRGB8->Numeric.LinearAlgebra.Matrix Word8
imgToMatrix Image { imageWidth = w, imageHeight = h, imageData = vec } = ((3*w)><h) (Data.Vector.Storable.toList vec)
matrixToImg::Numeric.LinearAlgebra.Matrix Word8-> Image PixelRGB8
matrixToImg matrix = Image (rows matrix `quot` 3) (cols matrix) (vectorToStorableVector (Numeric.LinearAlgebra.Data.flatten(matrix)))
where vectorToStorableVector vec= Data.Vector.Storable.fromList $ Numeric.LinearAlgebra.Data.toList vec
謝謝。
請張貼再現您的錯誤的確切代碼。 – leftaroundabout
我添加了導入。此代碼重現錯誤 – Alon
具有'Element'實例的類型是'Float'' Double','Complex Float'和'Complex Double'。也就是說,你不能用'Word8'做到這一點。如果例如我把浮法代替,這編譯罰款http://sprunge.us/WTIK – Michael