-
Notifications
You must be signed in to change notification settings - Fork 23
/
AvgSum.hs
36 lines (32 loc) · 1.26 KB
/
AvgSum.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Data.Default
import Data.Massiv.Array as A
import Data.Massiv.Array.IO
arrLightIx2 :: Comp -> Ix2 -> Array D Ix2 Double
arrLightIx2 comp arrSz = makeArray comp (Sz arrSz) lightFunc
where
lightFunc (i :. j) = sin (fromIntegral (i ^ (2 :: Int) + j ^ (2 :: Int)) :: Double)
{-# INLINE arrLightIx2 #-}
main :: IO ()
main = do
let arr = computeAs S $ arrLightIx2 Par (600 :. 800)
toImage
:: (Functor (Array r Ix2), Load r Ix2 (Pixel (Y' SRGB) Word8))
=> Array r Ix2 Double
-> Image S (Y' SRGB) Word8
toImage = computeAs S . fmap (PixelY' . toWord8)
lightPath = "files/light.png"
lightImage = toImage $ delay arr
lightAvgPath = "files/light_avg.png"
lightAvgImage = toImage $ mapStencil Edge (avgStencil 3) arr
lightSumPath = "files/light_sum.png"
lightSumImage = toImage $ mapStencil Edge (sumStencil 3) arr
writeImage lightPath lightImage
putStrLn $ "written: " ++ lightPath
writeImage lightAvgPath lightAvgImage
putStrLn $ "written: " ++ lightAvgPath
writeImage lightSumPath lightSumImage
putStrLn $ "written: " ++ lightSumPath
displayImageUsing defaultViewer True . computeAs S
=<< concatM 1 [lightAvgImage, lightImage, lightSumImage]