Which haskell library will let me save a 2D array/vector to a png/jpg/gif… file?

后端 未结 4 1135
走了就别回头了
走了就别回头了 2020-12-31 05:52

I am playing around with haskell, starting with simple plotting programs to wet my feet. I need a library that will let me save a 2D array/vector to an image file. I don\'t

4条回答
  •  执笔经年
    2020-12-31 06:32

    A new combination is:

    • repa; for n-dimensional arrays, plus
    • repa-devil, for image loading in dozens of formats.

    Repa is the only widely used array library that is automatically parallelized.

    An example, from the repa tutorial, using readImage and writeImage, to read an image, rotate it, and write it back out, in whatever format:

    import System.Environment
    import Data.Word
    import Data.Array.Repa hiding ((++))
    import Data.Array.Repa.IO.DevIL
    
    main = do
        [f] <- getArgs
        runIL $ do
            v   <- readImage f
            writeImage ("flip-"++f) (rot180 v)
    
    rot180 :: Array DIM3 Word8 -> Array DIM3 Word8
    rot180 g = backpermute e flop g
        where
            e@(Z :. x :. y :. _)   = extent g
    
            flop (Z :. i         :. j         :. k) =
                 (Z :. x - i - 1 :. y - j - 1 :. k)
    

提交回复
热议问题