Skip to content

Request to Update Vertical Edge Filter Implementation in Convolution Notebook #48

Description

@ahernandezhn

I am writing to suggest an improvement in the implementation of the vertical edge filter in the notebook located at:

https://github.com/davidADSP/Generative_Deep_Learning_2nd_Edition/blob/main/notebooks/02_deeplearning/02_cnn/convolutions.ipynb

Current Implementation Issues:
The current implementation uses negative indexing, which can lead to confusion and incorrect results, especially at the borders of the image. This approach might not correctly apply the convolution filter, affecting the accuracy of feature extraction. Specially when i=0 and j=0 and when evaluating im_pad[i - 1, j - 1] * filter1[0, 0] we are applying the filter to pixels that are sparce in the image patch. Instead of getting the top left of the image we are getting the bottom right.

Proposed Fix:
To address these issues, I propose the following code change:


new_image = np.zeros_like(im)
im_pad = np.pad(im, 1, "constant")

for i in range(im.shape[0]):
    for j in range(im.shape[1]):
        patch = im_pad[i:i+3, j:j+3]
        new_image[i, j] = np.sum(patch * filter1)

This implementation avoids negative indexing and ensures that the filter is correctly applied over the padded image.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions