我有一个类型的图像Image VS Y Double
(使用readImageY
HIP 库中的函数后),我想将其转换为Image VS Y Word8
. 我该怎么做呢?我需要在这个精度下应用它的下一个函数。
以下是相关代码的片段:
import Codec.Picture
import Codec.Picture.Types
import Control.Arrow
import Data.Ratio
import Data.Monoid
import Graphics.Image.Processing
import qualified Graphics.Image as I
import Graphics.Image.IO
import Graphics.Image.IO.Formats
import Graphics.Image.Interface.Vector
import qualified Graphics.Image.Interface as Interface
import Data.Word (Word8)
import qualified Data.Matrix as M
import System.FilePath.Posix (splitExtension)
to2DMatrix :: FilePath -> FilePath -> Border(Interface.Pixel I.Y Word8) -> (Int, Int) -> IO ()
to2DMatrix fp fpout bor (dim1, dim2)= do
eimg <- I.readImageY VS fp
let new_res :: Interface.Image VS I.Y Word8
new_res = I.resize Bilinear bor (dim1, dim2) eimg
let rle = twoDToMatrix $ pixelToInt $ toJPImageY8 new_res
let (name, _) = splitExtension fp
writeFile (name ++ ".txt") (show rle)
writeImage fpout rle
这是错误:
Couldn't match type ‘Double’ with ‘Word8’
Expected type: Interface.Image VS I.Y Word8
Actual type: Interface.Image VS I.Y Double
• In the fourth argument of ‘resize’, namely ‘eimg’
In the expression: resize Bilinear bor (dim1, dim2) eimg
In an equation for ‘new_res’:
new_res = resize Bilinear bor (dim1, dim2) eimg
|
29 | new_res = I.resize Bilinear bor (dim1, dim2) eimg
| ^^^^
编辑: 双打是在图像类型中存储为 VS 向量类型的灰度像素值。我遇到的问题是可以访问双打以便能够转换它们。试图在这里解释/找到 HIP 库的方法,但我是 Haskell 的新手,无法弄清楚。