Skip to content

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

Closed

Conversation

rzimmerdev
Copy link
Contributor

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.

  • Add an algorithm?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Dec 20, 2022
Copy link

@algorithms-keeper algorithms-keeper bot left a 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):

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):

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:

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():

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:

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

tq so much!

ghost

This comment was marked as duplicate.

ghost

This comment was marked as duplicate.

ghost

This comment was marked as duplicate.

@ghost

This comment was marked as duplicate.

ghost

This comment was marked as duplicate.

"""
estimated_img = np.full(shape=degraded.shape, fill_value=1, dtype="float64")

for i in range(steps):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
using Fourier transformations.
using Fourier transforms.

Nitpick: "Fourier transforms", not "Fourier transformations"

Comment on lines +138 to +139
if kernel.shape[0] > matrix.shape[1] or kernel.shape[1] > matrix.shape[1]:
return matrix
Copy link
Contributor

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?

Comment on lines +227 to +231
input_file = str(input()).rstrip()
degraded = imageio.imread(input_file)

angle = int(input())
steps = int(input())
Copy link
Contributor

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)
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:

Copy link

@algorithms-keeper algorithms-keeper bot left a 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):

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):

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:

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():

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:

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Sep 27, 2023
Copy link

@algorithms-keeper algorithms-keeper bot left a 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):

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):

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:

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():

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:

@tianyizheng02
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html tests are failing Do not merge until tests pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants