这哈斯克尔库将让我一个二维数组/矢量保存为PNG / JPG / GIF文件...? [英] Which haskell library will let me save a 2D array/vector to a png/jpg/gif... file?

查看:176
本文介绍了这哈斯克尔库将让我一个二维数组/矢量保存为PNG / JPG / GIF文件...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Haskell的玩弄,用简单的绘图程序开始打湿我的脚。我需要一个图书馆,让我一个二维数组/矢量保存为图像文件。我不想写的颜色列表。我想用这都是为了阵列/矢量运算一样的容器,可以是(当然,的几乎的了)自动并行化。

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 want to write a list of colors. I want to use containers that are meant for array/vector like computations and can be (well, almost) automagically parallelized.

修改能够存储彩色图像是必须的。

EDIT Ability to store color images is a must.

推荐答案

我开始 PGM 库。这是一个非常简单的uncom pressed graymap的格式。几乎没有additinal依赖。您可以PGM转换为其他格式,ImageMagick的或其他工具。

I'd start with PGM library. This is a very simple uncompressed graymap format. Almost no additinal dependencies. You can convert PGM to other formats with ImageMagick or other tools.

PGM支持通用 IArray 接口,并应与大多数标准的Haskell阵列的工作。您可以轻松地用并行<一个数组计算href=\"http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html\"><$c$c>Control.Parallel.Strategies.

PGM supports generic IArray interface, and should work with most of the standard Haskell arrays. You can easily parallelize array computations with Control.Parallel.Strategies.

PGM用法示例:

ghci> :m + Data.Array Graphics.Pgm 
ghci> let a = accumArray (+) 0 ((0::Int,0::Int),(127,127)) [ ((i,i), 1.0::Double) | i <- [0..127] ]
ghci> arrayToFile "t.pgm" (fmap round a)

这是图像:

否则,您可以使用 codeC-图像魔鬼可节省拆箱阵列的许多图像格式。你需要魔鬼库了。而你需要的所有阵列转换为特定类型它们( UArray(智力,INT,INT)Word8 )。

Otherwise you may use Codec-Image-DevIL which can save unboxed arrays to many of the image formats. You'll need DevIL library too. And you'll need to convert all arrays to that particular type of them (UArray (Int, Int, Int) Word8).

最后,如果你要流血的边缘,你可以考虑 repa 并行阵列和相应的 repa-IO 库,它可以把它们写<一个href=\"http://hackage.haskell.org/packages/archive/repa-io/1.1.0.0/doc/html/Data-Array-Repa-IO-BMP.html\">to BMP图像的。不幸的是,今天的 repa 还没有与新的GHC 7.0.2可建及旧GHC 6.12不给的性能优势。

Finally, if you want bleeding edge, you may consider repa parallel arrays and corresponding repa-io library, which can write them to BMP images. Unfortunately, today repa is not yet buildable with the new GHC 7.0.2 and doesn't give performance advantages on old GHC 6.12.

这篇关于这哈斯克尔库将让我一个二维数组/矢量保存为PNG / JPG / GIF文件...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆