Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ah-hn opened this issue Jan 6, 2025 · 0 comments

Comments

@ah-hn
Copy link

ah-hn commented Jan 6, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant