summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/c/iiConv2.c
blob: 436b2060c6839f0b3bc41ec316be655292c7f9e8 (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
55
/********************************
Author: Sravanthi Kota Venkata
********************************/

#include "sdvbs_common.h"

I2D* iiConv2(I2D* a, I2D* b)
{
    I2D *c;
    I2D *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 = iSetArray(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 = iMallocHandle(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;
}