- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在通过尝试大量的 programming examples 来探索 Haskell repa 库。我的目标是使用 repa 实现常见的图像处理算法。
有一些helpful code examples在 repa 存储库中。它们都对Array U DIM2 a
或Array DIM2 Float
或Array U DIM2 Double
类型的图像进行操作。
-- three image types used below
type Image = Array U DIM2 Double
type Image = Array DIM2 Float
type Image = Array U DIM2 (Word8, Word8, Word8)
-- examples/Blur/src-repa/Main.hs
blur :: Monad m => Int -> Array U DIM2 Double -> m (Array U DIM2 Double)
-- examples/Laplace/src-repa/SolverStencil.hs
solveLaplace :: Monad m => Int -> Array U DIM2 Double -> Array U DIM2 Double -> Array U DIM2 Double -> m (Array U DIM2 Double)
-- examples/Sobel/src-repa/SolverSeparated.hs
type Image = Array DIM2 Float
gradientX_sep :: Image -> Image
gradientX1 :: Image -> Image
gradientX2 :: Image -> Image
gradientY_sep :: Image -> Image
gradientY2 :: Image -> Image
-- examples/Canny/src-repa/Main.hs
type Image a = Array U DIM2 a
toGreyScale :: Image (Word8, Word8, Word8) -> IO (Image Float)
blurSepX :: Image Float -> IO (Image Float)
blurSepY :: Image Float -> IO (Image Float)
gradientX :: Image Float -> IO (Image Float)
gradientY :: Image Float -> IO (Image Float)
suppress :: Float -> Float -> Image (Float, Word8) -> IO (Image Word8)
wildfire :: Image Word8 -> Array U DIM1 Int -> IO (Image Word8)
selectStrong :: Image Word8 -> IO (Array U DIM1 Int)
gradientMagOrient :: Float -> Image Float -> Image Float -> IO (Image (Float, Word8))
图像文件IO有两种选择:
repa-examples 包中的图像类型为Array F DIM3 Word8
,如果是灰度图像,则类型为Array F DIM2 Word8
。这意味着repa-devil不能用于读取要与repa-examples中的示例一起处理的图像,因为repa-examples中的图像是二维数组,而repa-devil中的图像是三维数组。
readImage :: FilePath -> IL Image
writeImage :: FilePath -> Image -> IL ()
data Image = RGBA (Array F DIM3 Word8)
| RGB (Array F DIM3 Word8)
| BGRA (Array F DIM3 Word8)
| BGR (Array F DIM3 Word8)
| Grey (Array F DIM2 Word8)
repa-examples 和 repa-io 之间有更密切的对应关系。
readImageFromBMP :: FilePath -> IO (Either Error (Array U DIM2 (Word8,Word8, Word8)))
writeImageToBMP :: FilePath -> Array U DIM2 (Word8, Word8, Word8) -> IO ()
这次,BMP 图像文件被解析为一个二维数组,其元素类型为 (Word8,Word8,Word8)
,大概表示 R、G 和 B 值。即便如此,repa-examples 包中唯一兼容的函数是上面的 toGreyScale
。所有其他函数都对 Array U DIM2 Float
或 Array DIM2 Float
或 Array U DIM2 Double
类型的值进行操作。
toGreyScale
之外,repa-examples 中的所有示例都只适合在灰度图像上使用吗?虽然从类型来看这是有意义的,但令人惊讶的是没有彩色图像的修复示例。例如,为什么 blur
的类型不是:blur::Monad m => Int -> Array U DIM2 (Word8, Word8, Word8) -> m (Array U DIM2 (Word8, Word8, Word8))
最佳答案
Array U DIM2 Float
的图像,元素的范围通常为 0.0 - 1.0
。repa-io
包中,因为这会导致对外部编解码器库的依赖。使用其他软件包之一(例如 repa-devil
)来加载图像。repa-devil
包包装了外部 DevIL 库,因此加载的图像最终位于外部内存中 - 因此 F
索引位于 Array F DIM3 Word8 中
。 DevIL 库本身不知道如何在 Haskell 堆中构建未装箱的 U
数组。
这些示例只是示例,我并不想让 repa-examples
成为一个功能齐全的图像处理库。事实上,有些数组使用外部 F
表示,有些数组使用未装箱的 U
表示,这反射(reflect)了包装外部代码的标准问题。如果您想要一个统一的图像处理 API,那么您要么需要更改边界处的图像表示(这可能会引入冗余复制),要么使函数更加多态(这会使它们的类型变得复杂),要么以某种方式隐藏问题(这会导致成本增加)。模型不明显)。无论您选择哪个选项,都会有人提示。
关于haskell - 使用 Haskell repa 数组库进行彩色图像文件 IO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21098864/
两个相关的问题。 有没有 repa 的可变(ST monad)实现的原因?数组?相当于 Data.Vector.Mutable但有一个形状。 与此相关,应该如何在未装箱的表示中实现动态编程算法(从 相
我在 Haskell 库 Repa 中开发了一个如下定义的累积求和函数。但是,当将此功能与转置操作结合使用时,我遇到了一个问题。以下所有 3 项操作都需要不到一秒钟的时间: cumsum $ cums
在 haskell 中使用 repa,有没有一种方法可以打印矩阵,以便它们的格式很好,矩阵行位于单独的行上(大多数数值计算环境(如 R 或 matlab)的默认设置)? 我可以写一个,但它似乎已经存在
我真的很喜欢 Repa 的界面,即使它的并发能力如何。我实际上需要 repa 的数组是连续的,因为我的数组相对较小,并且它们的并行化是无用的,甚至是有害的。 但是,我确实在程序中使用了并行化,因此我将
以下代码会产生(可怕的)“嵌套并行性”错误 repa-3.4.0.1 : import Control.Monad.Identity (runIdentity, liftM) import Data.
在数值 Haskell Repa 教程中 Wiki ,有一段文字如下(用于上下文): 10.1 Fusion, and why you need it Repa depends critically
最好的制作方法是什么 type Configuration = Array DIM1 (Double, Double, Double) Read 的一个实例?所以后来我可以得出 data Simula
我想知道repa中是否有(//)的类似物? 无法并行化的数组转换需要它。例如,如果函数需要整个数组来更改数组的单个条目,然后将其应用于新数组等等(并且它应该按顺序运行)。 最佳答案 (//)可以用Da
问题 我试图了解 Repa工作,我从 Repa Examples 得到一个“模糊”示例代码。包裹。代码使用 stencil2 Quasi Quote : [stencil2| 2 4 5 4
我正在编写一个生成图像的程序,我想将其带入 Repa 数组。我目前使用的类型: data Colour = Colour Double Double Double 来表示像素,我有一个(可能效率低下但
我想实现类似于标准数组包中的有界数组但使用 repa 数组的东西。 实现这一目标的好方法是什么? 这是我尝试过的,但必须有比将所有内容包装在检查边界的自定义函数中更好的方法: import Data
假设我想使用有限差分法为看涨期权定价 然后再做以下工作: import Data.Array.Repa as Repa r, sigma, k, t, xMax, deltaX, deltaT ::
我使用 Euler symplectic method 编写了太阳系外行星的模拟。并使用 repa 和 b) 使用 yarr 实现了这一点。 yarr seems to perform about x
在我最近的 work与 Gibbs sampling ,我一直在充分利用 RVar 在我看来,它为随机数生成提供了一个近乎理想的接口(interface)。遗憾的是,由于无法在 map 中使用 mon
我正在尝试使用 Repa 实现累积和函数以计算积分图像。我当前的实现如下所示: cumsum :: (Elt a, Num a) => Array DIM2 a -> Array DIM2 a cum
我正在从磁盘加载 RGB 图像 JuicyPixels-repa 。不幸的是,图像的数组表示是 Array F DIM3 Word8其中内部维度是 RGB 像素。这与现有的repa有点不兼容。 RGB
假设我想将一个函数映射到一个数组上,但该函数的类型不仅仅是 a -> b但 a -> 整数 -> b即该函数还需要一个索引。我该怎么做? 最佳答案 简短回答,使用遍历。 更长的例子: import q
问题 我正在寻找 repa 库中可能已经存在的函数。我想要一个功能: 接受一个二维数组 指定窗口大小的两个整数 在二维数组上给定大小的每个窗口中,计算一个新值,例如此特定窗口中的小值。 例子 用 3x
Repa的所有归约函数折叠回与数组内容相同的类型。例如: foldAllP :: (Shape sh, Source r a, Elt a, Unbox a, Monad m) => (a -> a
在 GNU Octave 中此代码 - [e, ix] = min(X); 将返回最小元素及其位置。 如何在 repa 中实现任意二进制函数? 这是我想到的: min x = z $ foldl' f
我是一名优秀的程序员,十分优秀!