在Haskell中向图像添加高斯噪声

时间:2018-08-18 08:39:12

标签: haskell image-processing gaussian

我正在尝试实现一种向Haskell中的图像添加高斯噪声的算法。这是我到目前为止编写的代码:

    gaussianNoise
       :: forall arr e cs . (MArray arr Y Double, IP.Array arr Y Double)
       => Image arr Y Double
       -> Float  -- ^ Mean
       -> Float  -- ^ Sigma
       -> StdGen -- ^ Instance of RandomGen
       -> Image arr Y Double
    gaussianNoise image mean sigma g = accBin g
     where
       widthMax, heightMax :: Int
       widthMax = ((rows image) - 1)
       heightMax = ((cols image) - 1)
       samples = normals' (mean, sigma) g

       -- need samples to be resized to widthMax x heightMax

       accBin :: [] -> Image arr Y Double  -- This needs to be corrected
       accBin samples = runST $ 
          do arr <- I.thaw image  
             forM_ [0 .. widthMax] $ \x -> do
               forM_ [0 .. heightMax] $ \y -> do  
                 let px = ( (I.index image (x, y)) + (PixelX (fromIntegral (samples ! (x, y) ) )) )
                 I.write arr (x, y) px
             freeze arr

我想使用以下软件包https://github.com/lehins/hip。 我很困惑如何将samples调整为2d格式,然后在accBin中使用相同的格式。一些解释/实现此目的的正确代码将对我很有帮助。

谢谢!

0 个答案:

没有答案
相关问题