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

doing a convolve2d in valid mode but return same size. #9923

Open
nickylimjj opened this issue Mar 8, 2019 · 4 comments
Open

doing a convolve2d in valid mode but return same size. #9923

nickylimjj opened this issue Mar 8, 2019 · 4 comments
Labels
enhancement A new feature or improvement scipy.signal

Comments

@nickylimjj
Copy link

I understand that there are 3 modes for convolving and correlating. For valid mode, it outputs a smaller image as it only convolves the valid elements. I believe it should be a core functionality to convolves in valid mode but output the same size image padded with fill_value

@rgommers
Copy link
Member

rgommers commented Mar 8, 2019

I understand that there are 3 modes for convolving and correlating.

For signal.convolve/correlate, indeed. ndimage.convolve/correlate always returns the same size, which is usually what you want for image processing type applications. what is your use case? I can imagine why your proposal would be useful, but only fill_value=np.nan would be a sensible default.

@rgommers rgommers added scipy.signal enhancement A new feature or improvement labels Mar 8, 2019
@nickylimjj
Copy link
Author

nickylimjj commented Mar 9, 2019

My use case is for image convolution. I am a student in a computer vision class and we are using the scipy.signal library for convolve2d and wanted to get the same output size for valid convolution and pad the rest with 0s. Our hacky solution is to return a smaller image and embed it in a new image of original size. Perhaps it is better for the ndimage library, but it seems like that doesn't have a simple function call for that behavior either.

@rgommers
Copy link
Member

rgommers commented Mar 9, 2019

Perhaps it is better for the ndimage library, but it seems like that doesn't have a simple function call for that behavior either.

Indeed. No one has asked for it before. The reason I think is simply that filling with zeros is arbitrary, and should be strictly worse than using ndimage.convolve with mode='constant', cval=0. That way you get results that are between zero and the "right" answer.

@rfezzani
Copy link

What about returning the values of the input array unchanged where the convolution is not 'valid'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.signal
Projects
None yet
Development

No branches or pull requests

3 participants