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

Lens Blur node #1516

Merged
merged 5 commits into from
Feb 4, 2023
Merged

Lens Blur node #1516

merged 5 commits into from
Feb 4, 2023

Conversation

harisreedhar
Copy link
Contributor

@harisreedhar harisreedhar commented Jan 29, 2023

Add lens blur node
Screenshot from 2023-01-29 13-24-52

Add lens blur node
@harisreedhar harisreedhar changed the title Create blur_lens.py Lens Blur node Jan 29, 2023
Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @harisreedhar!

I looked through your code and have a few suggestions.
Also, please format the new code with black.

@RunDevelopment
Copy link
Member

@joeyballentine Does opencv or numpy include scipy?

@joeyballentine
Copy link
Member

@RunDevelopment I don't think so, so that means we would need to add that as another dependency. It's actually required by facexlib so anyone who has the pytorch deps installed already has it.

@harisreedhar
Copy link
Contributor Author

harisreedhar commented Jan 30, 2023

@RunDevelopment I don't think so, so that means we would need to add that as another dependency. It's actually required by facexlib so anyone who has the pytorch deps installed already has it.

scipy.signal.convolve2d can be replaced with this function. So no need to add extra dependency.

def conv2d(a, f):
    s = f.shape + tuple(np.subtract(a.shape, f.shape) + 1)
    strd = np.lib.stride_tricks.as_strided
    subM = strd(a, shape = s, strides = a.strides * 2)
    return np.einsum('ij,ijkl->kl', f, subM)

EDIT: Above function produces small square blocks in image. not same as scipy.signal :(

1675056977 459564

@RunDevelopment
Copy link
Member

Maybe we could use cv2.filter2D? That one also does a convolution.

@harisreedhar
Copy link
Contributor Author

Maybe we could use cv2.filter2D? That one also does a convolution.

Found gimp lens blur filter using cv2.filter2D. It is faster than current implementation

Use gimp lens blur filter to eliminate scipy dependency
@RunDevelopment
Copy link
Member

It is faster than current implementation

Holy, it's waaay faster. Nice! My little test example dropped from 51s to 4.3s, so it's over 10x faster.

@joeyballentine joeyballentine merged commit 3426983 into chaiNNer-org:main Feb 4, 2023
@harisreedhar harisreedhar deleted the lens_blur branch February 5, 2023 17:23
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

Successfully merging this pull request may close these issues.

3 participants