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

Avoid empty kernel #28

Closed
wants to merge 3 commits into from
Closed

Conversation

mawc2019
Copy link
Collaborator

In this PR, the situation of an empty kernel is avoided and #23 is fixed. The variable shape is renamed as kernel_size to avoid confusion with another variable kernel_shape and the Python command .shape.


if shape[0] <= 2 and shape[1] <= 2:
return np.ones(shape, dtype=np.uint8)
if kernel_size[0] <= 2 and kernel_size[1] <= 2:
Copy link
Contributor

Choose a reason for hiding this comment

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

What about non-square kernels, e.g. kernel_size[0] == 0 and kernel_size[1] == 3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This PR did not take care of this situation. The fix should be revised as something like:

  if kernel_size in np.array([[2,2], [2,1], [1,2], [2,1]]):
    return np.ones(kernel_size, dtype=np.uint8)

  if kernel_size[0] == 0 or kernel_size[1] == 0:
    return np.array([[1]], dtype=np.uint8)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the revised PR, I used the following lines instead:

  if kernel_size[0] == 0 or kernel_size[1] == 0:
    return np.array([[1]], dtype=np.uint8)
  elif kernel_size in np.array([[2,2], [2,1], [1,2], [2,1]]):
    return np.ones(kernel_size, dtype=np.uint8)
  else:
    rounded_size = np.round(diameter / pixel_size - 1) * pixel_size

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually support non-square kernels?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the code including its early versions supports non-square kernels, which typically arise if a pixel has different sizes in x and y directions.

@stevengj
Copy link
Contributor

Closed by #30

@stevengj stevengj closed this Mar 28, 2024
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.

2 participants