1

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++)
1
  • In first method you will cover entire image, where as in second you will miss boundary by one pixel. Commented Mar 20, 2014 at 12:01

2 Answers 2

1

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")

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

is the code for(int y = 0; y < grey.rows; y++) for(int x = 0; x < grey.cols; x++) to iterates pixel in the border of array?
these two nested loops iterate over all the pixels of the image, borders included.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.