Quantcast
Channel: Intel® Cilk™ Plus
Viewing all articles
Browse latest Browse all 77

Image processing average filter sample code

$
0
0

The following code is taken from https://software.intel.com/en-us/code-samples/intel-c-compiler/application-domains/finance/averaging-filter 
here is the serial code which is not hard to explain

Linear Version of the code

for(int i = 1; i < (h+1); i++)
{
    int x = ((resized_width * i) + 1);
    for(int j = x; j < (x + w); j++)
    {
        unsigned int red = 0, green = 0, blue = 0;
        for(int k1 = (-1); k1 <= 1; k1++)
        {
            int pos = j + (k1 * resized_width);
            for(int k2 = (-1); k2 <= 1; k2++)
            {
                red += resized_indataset[(pos + k2)].red;
                green += resized_indataset[(pos + k2)].green;
                blue += resized_indataset[(pos + k2)].blue;
            }
        }
        resized_outdataset[j].red = red/9;
        resized_outdataset[j].green = green/9;
        resized_outdataset[j].blue = blue/9;
    }
}

Array Notation

for(int i = 1; i < (h+1); i++)
{
    int x = ((resized_width * i) + 1);
    for(int j = x; j < (x + w); j+=8)
    {
        int row2index = 3*j - 3;
        int jump = (resized_width * 3);
        int row1index = row2index - jump;
        int row3index = row2index + jump;
        out[(row2index + 3):24] = (in[row1index:24] + in[row1index+3:24] + in[row1index+6:24] + in[row2index:24] + in[row2index+3:24] + in[row2index+6:24] + in[row3index:24] + in[row2index+3:24] + in[row2index+6:24])/9;
    }
}

I'm trying to understand the code but I do not understand that basics assumption here.

In the following code

  for(int j = x; j < (x + w); j+=8)
        {
            int row2index = 3*j - 3;
            int jump = (resized_width * 3);
            int row1index = row2index - jump;
            int row3index = row2index + jump;
            out[(row2index + 3):24] = (in[row1index:24] + in[row1index+3:24] + in[row1index+6:24] + in[row2index:24] + in[row2index+3:24] + in[row2index+6:24] + in[row3index:24] + in[row3index+3:24] + in[row3index+6:24])/9;
        }

a.how do you decide that j needs to jump to j+=8 ? why 8?
b.why does jump = (resized_width * 3)?
c.why do we have index +0, index+3 ,index +6 ??


Viewing all articles
Browse latest Browse all 77

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>