public
Created

applyWindowFunction

  • Download Gist
applyWindow.hs
Haskell
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 37 38 39 40 41 42 43 44
{-# RULES
"applyWindow/applyWindow" forall win1 win2 image. applyWindow win1
(applyWindow win2 image) =
applyWindow (indexMult win1 win2) image
#-}
 
applyWindow window imageArray =
let ((windowWidthMin, windowHeightMin), (windowWidthMax, windowHeightMax)) = bounds window -- keep
windowWidth = windowWidthMax - windowWidthMin -- Keep Calculated
windowHeight = windowHeightMax - windowHeightMin -- Keep Cakculated
w = (floor (fromIntegral(windowWidth) / 2)) :: Int -- Keep
h = (floor (fromIntegral(windowHeight) / 2)) :: Int -- Keep
((imageWidthMin, imageHeightMin), (imageWidthMax, imageHeightMax)) = bounds imageArray -- Keep
paddedImage =
array
((imageWidthMin-w,imageHeightMin-h),(imageWidthMax+w,imageHeightMax+h))
[ ((i,j), if i >= imageWidthMin &&
j >= imageHeightMin &&
i <= imageWidthMax &&
j <= imageHeightMax
then imageArray ! (i,j)
else 0
) |
i <- [imageWidthMin-w..imageWidthMax+w],
j <- [imageHeightMin-h..imageHeightMax+h]]
filteredPaddedImage = {-# SCC "filter" #-}
array
((imageWidthMin-w,imageHeightMin-h),(imageWidthMax+w,imageHeightMax+h))
[((i,j), if i >= imageWidthMin &&
j >= imageHeightMin &&
i <= imageWidthMax &&
j <= imageHeightMax
then {-# SCC "sum" #-} sum [{-# SCC "list" #-} ((paddedImage!(i+m,j+n)) * window!(m,n)) |
m <- {-# SCC "m" #-} [windowWidthMin..windowWidthMax],
n <- {-# SCC "n" #-} [windowHeightMin..windowHeightMax]]
else 0
) |
i <- [imageWidthMin-w..imageWidthMax+w],
j <- [imageHeightMin-h..imageHeightMax+h]]
in array -- Is this necessary? or can we just return filteredPaddedImage
((imageWidthMin, imageHeightMin), (imageWidthMax, imageHeightMax))
[((i,j), (filteredPaddedImage!(i,j)) ) |
i <- [imageWidthMin .. imageWidthMax],
j <- [imageHeightMin .. imageHeightMax]]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.