Jump to content
Sign in to follow this  
rapot

Array convolution

Recommended Posts

rapot

I was looking around forum but AutoIt but do not found any topic to write about Convolution two array.

I just found this>>Convolution.Au3

It Convolution with image.So i find function Convolution two array with assembly in autoit

Anyone can write a function Convolution like this:

http://www.ece.umd.edu/~tretter/commlab/c6713slides/convol1.sa

Please share me

Thanks

Convolution.au3

Fasm.rar

Share this post


Link to post
Share on other sites
MvGulik

Sure they can.

Question is will they.

What you think MOD. Naa they wont.

O wait ... let me help you a little.

I was looking around forum but AutoIt but do not found any topic to write about Convolution two array.

I just found this>>Convolution.Au3

It Convolution with image.So i find function Convolution two array with assembly in autoit

Anyone can write a function Convolution like this:

http://www.ece.umd.edu/~tretter/commlab/c6713slides/convol1.sa

Please share me

Thanks


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Malkey

Here is an attempt at convoluting two 2D arrays.

I do not know whether the results are conventionally correct or not.

#include <Array.au3>
; Ref: http://www.songho.ca/dsp/convolution/convolution2d_example.html

Local $arr[5][5] = [ _
        [1, 2, 3, 4, 5], _
        [6, 7, 8, 9, 10], _
        [11, 12, 13, 14, 15], _
        [16, 17, 18, 19, 20], _
        [21, 21, 23, 24, 25]]


Local $k[3][3] = [ _
        [0, -1, 0], _
        [0, 2, 0], _
        [0, 0, 0]]
Local $aAnswer = _ArrayConvolve($arr, $k)
_ArrayDisplay($aAnswer, "Convolve Arrays 5x5 and 3x3")


Local $k2[2][2] = [[1, 0],[0, 1]]
Local $aAnswer2 = _ArrayConvolveEx($arr, $k2)
_ArrayDisplay($aAnswer2, "Convolve Arrays 5x5 and 2x2")


; Only accepts array $k being [Ubound ($k) = odd number] and [Ubound ($k, 2) = odd number].
Func _ArrayConvolve($arr, $k)
    Local $aResult[UBound($arr)][UBound($arr, 2)]
    Local $sum = 0
    For $x = 0 To UBound($arr) - 1
        For $y = 0 To UBound($arr, 2) - 1
            $sum = 0
            For $i = -Int(UBound($k) / 2) To Int(UBound($k) / 2)
                For $j = -Int(UBound($k, 2) / 2) To Int(UBound($k, 2) / 2)
                    If $x + $i >= 0 And ($x + $i < UBound($arr)) And $y + $j >= 0 And ($y + $j < UBound($arr, 2)) Then _
                            $sum += $arr[$x + $i][$y + $j] * $k[$i + Int(UBound($k) / 2)][$j + Int(UBound($k, 2) / 2)]
                Next
            Next
            $aResult[$x][$y] = $sum
        Next
    Next
    Return $aResult
EndFunc   ;==>_ArrayConvolve

; Accepts any size $k array.
Func _ArrayConvolveEx($arr, $k)
    Local $aResult[UBound($arr)][UBound($arr, 2)]
    Local $sum = 0
    For $x = 0 To UBound($arr) - 1
        For $y = 0 To UBound($arr, 2) - 1
            $sum = 0
            For $i = -Int(UBound($k) / 2) To Int(UBound($k) / 2) - (1 * Mod(UBound($k), 2) = 0)
                For $j = -Int(UBound($k, 2) / 2) To Int(UBound($k, 2) / 2) - (1 * Mod(UBound($k, 2), 2) = 0)
                    If $x + $i >= 0 And ($x + $i < UBound($arr)) And $y + $j >= 0 And ($y + $j < UBound($arr, 2)) Then _
                            $sum += $arr[$x + $i][$y + $j] * $k[$i + Int(UBound($k) / 2)][$j + Int(UBound($k, 2) / 2)]
                Next
            Next
            $aResult[$x][$y] = $sum
        Next
    Next
    Return $aResult
EndFunc   ;==>_ArrayConvolveEx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.