user3441817
user3441817

Reputation: 11

Convolution of array

What is different between these convolution algorithms?

Why y=0 and y<1, x = 0; x < 1 and the other y=1 and y <-1, x < - 1.

for(int y = 0; y < grey.rows; y++)
    for(int x = 0; x < grey.cols; x++)
        dst.at<uchar>(y,x) = 0;  

This is the second convolution:

for(int y = 1; y < grey.rows - 1; y++){
    for(int x = 1; x < grey.cols - 1; x++)

Upvotes: 1

Views: 1123

Answers (2)

Sigi
Sigi

Reputation: 4926

In the first two for-loops the code is just initializing the probable result array.

In the second two loops the convolution involves a convolution kernel that is 3x3, so the code in the loop will reference to elements starting from dst.at<uchar>(y-1 , x-1) to dst.at<uchar>(y+1 , x+1).

So the kernel cannot be evaluated on the borders, but just starting for pixels placed from 1 instead of 0 and ending to n-2 instead of n-1.

Upvotes: 1

Sga
Sga

Reputation: 3658

The first loop isn't properly a "convolution" since the assign operation has a "kernel" of size 1. The second example seems to use a kernel of size 3, so it needs 3 pixels to work: prev/curr/next (that's why the for loops are "shorter")

Upvotes: 1

Related Questions