Created
February 12, 2012 18:53
-
-
Save HepaxCodex/1810229 to your computer and use it in GitHub Desktop.
applyWindowFunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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