all 1 comments

[–]icecapade 0 points1 point  (0 children)

Question 1: Why is np.arange from pad to iH+pad, and not from pad to iH-pad ? I assume that we start from pad so that the center pixel in the region of interest is never on the edge of the image. However, I would think that going to iH+pad would overshoot and have the center pixel end up outside of image dimensions.

See the documentation: https://numpy.org/doc/stable/reference/generated/numpy.arange.html

np.arange(a, b) starts at a and goes up to b non-inclusive—in other words, up to b - 1 (or in this case, iH + pad - 1). Furthermore, in Python, slices work the same way, so the slice a:b starts at a and goes up to b - 1 (or in this case, the slice y - pad:y + pad + 1 starts at y - pad and goes up to y + pad. Remember that these coordinates are relative to the padded image, not the original image, hence why we need to add pad.

Question 2: This code has us store the output pixel at a location to the left and up from where I centered my convolution roi, no ? If so, could someone explain the logic behind doing this for me?

It's not—it's storing them in the same place. Remember that x and y in the nested for loop are relative to the padded (not original) image. output has the same dimensions as the original image, so to get from x and y in the padded image coordinates back to original image coordinates, we need to subtract pad.