summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/c/imageBlur.c
blob: 8e3ad923a8012ce22b3df660787d0fdb6bd9ab72 (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
56
57
58
59
60
61
62
63
64
65
66
67
/********************************
Author: Sravanthi Kota Venkata
********************************/

#include "sdvbs_common.h"

F2D* imageBlur(I2D* imageIn)
{
    int rows, cols;
    F2D *imageOut, *tempOut;
    float temp;
    I2D *kernel;
    int k, kernelSize, startCol, endCol, halfKernel, startRow, endRow, i, j, kernelSum;

    rows = imageIn->height;
    cols = imageIn->width;

    imageOut = fSetArray(rows, cols, 0);
    tempOut = fSetArray(rows, cols, 0);
    kernel = iMallocHandle(1, 5);

    asubsref(kernel,0) = 1;
    asubsref(kernel,1) = 4;
    asubsref(kernel,2) = 6;
    asubsref(kernel,3) = 4;
    asubsref(kernel,4) = 1;
    kernelSize = 5;
    kernelSum = 16;

    startCol = 2;  
    endCol = cols - 2;  
    halfKernel = 2;   

    startRow = 2;    
    endRow = rows - 2;  

    for(i=startRow; i<endRow; i++){
        for(j=startCol; j<endCol; j++)
        {
            temp = 0;
            for(k=-halfKernel; k<=halfKernel; k++)
            {
                temp += subsref(imageIn,i,j+k) * asubsref(kernel,k+halfKernel);
            }
            subsref(tempOut,i,j) = temp/kernelSum;
        }
    }
    
    for(i=startRow; i<endRow; i++)
    {
        for(j=startCol; j<endCol; j++)
        {
            temp = 0;
            for(k=-halfKernel; k<=halfKernel; k++)
            {
                temp += subsref(tempOut,(i+k),j) * asubsref(kernel,k+halfKernel);
            }
            subsref(imageOut,i,j) = temp/kernelSum;
        }
    }

    fFreeHandle(tempOut);
    iFreeHandle(kernel);
    return imageOut;
}