-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Deblur and Denoise using Richardson Lucy Deconvolution for Computer Vision tasks #8038
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
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
No! What if the Kernel is empty? Example: >>> kernel = np.zeros((1)) >>> kernel or np.ones((3, 3)) array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]) Co-authored-by: Christian Clauss <cclauss@me.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
return np.sqrt(((original - reference) ** 2).mean()) | ||
|
||
|
||
def pad_to_size(image: np.ndarray, reference: np.ndarray): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/richardson_lucy.py
, please provide doctest for the function pad_to_size
Please provide return type hint for the function: pad_to_size
. If the function does not return a value, please provide the type hint as: def function() -> None:
return normalized.astype(data_type) | ||
|
||
|
||
def gaussian_noise(size: tuple, mean=0, std=0.05): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: gaussian_noise
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: mean
Please provide type hint for the parameter: std
return noise | ||
|
||
|
||
def gaussian_filter(k: int = 5, sigma: float = 1.0) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: k
return estimated_img | ||
|
||
|
||
def main(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/richardson_lucy.py
, please provide doctest for the function main
Please provide return type hint for the function: main
. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tq so much!
This comment was marked as duplicate.
This comment was marked as duplicate.
computer_vision/richardson_lucy.py
Outdated
""" | ||
estimated_img = np.full(shape=degraded.shape, fill_value=1, dtype="float64") | ||
|
||
for i in range(steps): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i in range(steps): | |
for _ in range(steps): |
i
is never used in the loop body, and this is causing the pre-commit to fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong PR, already included in #8004
def convolve(matrix: np.ndarray, kernel: np.ndarray) -> np.ndarray: | ||
""" | ||
Convolves a given kernel around a matrix through the frequency domain, | ||
using Fourier transformations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using Fourier transformations. | |
using Fourier transforms. |
Nitpick: "Fourier transforms", not "Fourier transformations"
if kernel.shape[0] > matrix.shape[1] or kernel.shape[1] > matrix.shape[1]: | ||
return matrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the kernel is too big, why not raise an error?
input_file = str(input()).rstrip() | ||
degraded = imageio.imread(input_file) | ||
|
||
angle = int(input()) | ||
steps = int(input()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get prompt messages for the input
calls
|
||
def pad_to_size(image: np.ndarray, reference: np.ndarray): | ||
"""Pad an image to have final shape equal to reference image.""" | ||
p, q = (size for size in reference.shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these variables necessary? Why not just use reference.shape[0]
and reference.shape[1]
?
return ifftshift(ifft2(np.multiply(matrix_f, kernel_f))).real | ||
|
||
|
||
def get_motion_psf(shape: tuple, angle: float, num_pixel_dist: int = 20) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_motion_psf(shape: tuple, angle: float, num_pixel_dist: int = 20) -> np.ndarray: | |
def get_motion_psf(shape: tuple[int, int], angle: float, num_pixel_dist: int = 20) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
return np.sqrt(((original - reference) ** 2).mean()) | ||
|
||
|
||
def pad_to_size(image: np.ndarray, reference: np.ndarray): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/richardson_lucy.py
, please provide doctest for the function pad_to_size
Please provide return type hint for the function: pad_to_size
. If the function does not return a value, please provide the type hint as: def function() -> None:
return normalized.astype(data_type) | ||
|
||
|
||
def gaussian_noise(size: tuple, mean=0, std=0.05): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: gaussian_noise
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: mean
Please provide type hint for the parameter: std
return noise | ||
|
||
|
||
def gaussian_filter(k: int = 5, sigma: float = 1.0) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: k
return estimated_img | ||
|
||
|
||
def main(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/richardson_lucy.py
, please provide doctest for the function main
Please provide return type hint for the function: main
. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
return np.sqrt(((original - reference) ** 2).mean()) | ||
|
||
|
||
def pad_to_size(image: np.ndarray, reference: np.ndarray): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/richardson_lucy.py
, please provide doctest for the function pad_to_size
Please provide return type hint for the function: pad_to_size
. If the function does not return a value, please provide the type hint as: def function() -> None:
return normalized.astype(data_type) | ||
|
||
|
||
def gaussian_noise(size: tuple, mean=0, std=0.05): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: gaussian_noise
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: mean
Please provide type hint for the parameter: std
return noise | ||
|
||
|
||
def gaussian_filter(k: int = 5, sigma: float = 1.0) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: k
return estimated_img | ||
|
||
|
||
def main(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/richardson_lucy.py
, please provide doctest for the function main
Please provide return type hint for the function: main
. If the function does not return a value, please provide the type hint as: def function() -> None:
This PR is unfortunately taking too long and too much effort to fix, and I don't have the time because we maintainers have to clear out the backlog of PRs as much as possible before Hacktoberfest. In addition, it appears that this PR has failing doctests even when the code formatting and styling has been fixed. |
Describe your change:
I've added the Richardson Lucy deconvolution algorithm, as well as some supporting auxiliary methods.
This algorithm is useful for recovering degraded images, given a known noise and/or blurring function.
Checklist:
Fixes: #{$ISSUE_NO}
.