Skip to content

Instantly share code, notes, and snippets.

@HepaxCodex
Created February 12, 2012 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HepaxCodex/1810229 to your computer and use it in GitHub Desktop.
Save HepaxCodex/1810229 to your computer and use it in GitHub Desktop.
applyWindowFunction
{-# 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]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment