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

Reduce the complexity of digital_image_processing/edge detection/canny.py #8167

Conversation

MaximSmolskiy
Copy link
Member

@MaximSmolskiy MaximSmolskiy commented Mar 4, 2023

Describe your change:

Reduce the complexity of digital_image_processing/edge detection/canny.py from 17 to 11

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

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 include at least one URL that points to Wikipedia or another 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 labels Mar 4, 2023
@MaximSmolskiy MaximSmolskiy changed the title Reduce the complexity of digital image processing/edge detection/canny.py Reduce the complexity of digital_image_processing/edge detection/canny.py Mar 4, 2023
Copy link
Contributor

@CaedenPH CaedenPH left a comment

Choose a reason for hiding this comment

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

Nice change

@MaximSmolskiy
Copy link
Member Author

@cclauss please review

@@ -110,6 +115,24 @@ def canny(image, threshold_low=15, threshold_high=30, weak=128, strong=255):
else:
dst[row, col] = 0


def canny(image, threshold_low=15, threshold_high=30, weak=128, strong=255):
image_row, image_col = image.shape[0], image.shape[1]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
image_row, image_col = image.shape[0], image.shape[1]
image_row, image_col = image.shape

Copy link
Member

Choose a reason for hiding this comment

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

This function is not using image.shage so why bother unpacking it?

Make all the functions use image.shape instead of separate row and col.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 125 to 126
gradient_direction = np.rad2deg(sobel_theta)
gradient_direction += PI
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
gradient_direction = np.rad2deg(sobel_theta)
gradient_direction += PI
gradient_direction = PI + np.rad2deg(sobel_theta)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@cclauss
Copy link
Member

cclauss commented Apr 1, 2023

Are there tests?

@MaximSmolskiy MaximSmolskiy force-pushed the reduce-the-complexity-of-digital_image_processing/edge_detection/canny.py branch from 1ffa6e8 to a806c0d Compare April 1, 2023 15:57
an edge pixel's value is smaller than the low threshold value, it will be
suppressed.
"""
return dst
Copy link
Member

Choose a reason for hiding this comment

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

Why daylight savings time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to destination

@MaximSmolskiy
Copy link
Member Author

Are there tests?

No, there weren't tests. I ran the script before and after changes - there is no differences in output images.

@MaximSmolskiy MaximSmolskiy requested a review from cclauss April 1, 2023 16:18
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Apr 1, 2023
@cclauss cclauss merged commit 59cae16 into TheAlgorithms:master Apr 1, 2023
@MaximSmolskiy MaximSmolskiy deleted the reduce-the-complexity-of-digital_image_processing/edge_detection/canny.py branch April 1, 2023 16:23
tianyizheng02 pushed a commit to tianyizheng02/Python that referenced this pull request May 29, 2023
…y.py (TheAlgorithms#8167)

* Reduce the complexity of digital_image_processing/edge_detection/canny.py

* Fix

* updating DIRECTORY.md

* updating DIRECTORY.md

* updating DIRECTORY.md

* Fix review issues

* Rename dst to destination

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
…y.py (TheAlgorithms#8167)

* Reduce the complexity of digital_image_processing/edge_detection/canny.py

* Fix

* updating DIRECTORY.md

* updating DIRECTORY.md

* updating DIRECTORY.md

* Fix review issues

* Rename dst to destination

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants