summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/c/fResortIndices.c
blob: d4d1cda965c0d369bc185d6bf6332b6fc48d370c (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
68
69
70
71
72
73
74
75
76
77
/********************************
Author: Sravanthi Kota Venkata
********************************/

#include "sdvbs_common.h"

I2D* fResortIndices(F2D* input, int dim, F2D* in, I2D* ind)
{
    int rows, cols;
    //F2D *in;
    int i, j, k;
    //I2D *ind;

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

    in = fCopy(input, in);
    //ind = iMallocHandle(rows,cols);

    for(i=0; i<cols; i++) {
        for(j=0; j<rows; j++) {
            subsref(ind,j,i) = 0;
		}
	}

if(dim == 1)
{
    for(k=0; k<rows; k++)
    {
        for(i=0; i<cols; i++)
        {
            float localMax = subsref(in,k,i);
            int localIndex = i;
            subsref(ind,k,i) = i;
            for(j=0; j<cols; j++)
            {
                if(localMax < subsref(in,k,j))
                {
                    subsref(ind,k,i) = j;
                    localMax = subsref(in,k,j);
                    localIndex = j;
                }
            }
            subsref(in,k,localIndex) = 0;
        }
    }
    
    //fFreeHandle(in);
    return ind;
}

    for(k=0; k<cols; k++)
    {
        for(i=0; i<rows; i++)
        {
            float localMax = subsref(in,i,k);
            int localIndex = i;
            subsref(ind,i,k) = i;
            for(j=0; j<rows; j++)
            {
                if(localMax < subsref(in,j,k))
                {
                    subsref(ind,i,k) = j;
                    localMax = subsref(in,j,k);
                    localIndex = j;
                }
            }
            subsref(in,localIndex,k) = 0;
        }
    }

    //fFreeHandle(in);
    return ind;
}