summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/c/fiConv2.c
blob: 87fc4ec5a89256ce63e908f6b6e36ec416b9f81b (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
/********************************
Author: Sravanthi Kota Venkata
********************************/

#include "sdvbs_common.h"

F2D* fiConv2(I2D* a, F2D* b)
{
    F2D *c;
    F2D *out;
    int ma, na, mb, nb, ci, cj, i, j, m, n;
    int r_index, c_index;

    ma = a->height;
    na = a->width;

    mb = b->height;
    nb = b->width;
    
    r_index = ceil((mb + 1.0)/2.0);
    c_index = ceil((nb + 1.0)/2.0);

    ci = ma+mb-1;
    cj = na+nb-1;

    c = fSetArray(ci, cj, 0);

    for(i=0; i<ci; i++)
    {
        for(j=0; j<cj; j++)
        {
            for(m=0; m<ma; m++)
            {
                for(n=0; n<na; n++)
                {
                    if( (i-m)>=0 && (j-n)>=0 && (i-m)<mb && (j-n)<nb )
                        subsref(c,i,j) += subsref(a,m,n) * subsref(b,(i-m),(j-n));
                }
            }

        }
    }

    out = fMallocHandle(ma, na);
    for(i=0; i<ma; i++)
    {
        for(j=0; j<na; j++)
        {
            subsref(out,i,j) = subsref(c,(i+r_index-1),(j+c_index-1));
        }
    }

    return out;
}