-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
imageruler/imageruler.py
Outdated
|
||
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: |
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.
What about non-square kernels, e.g. kernel_size[0] == 0 and kernel_size[1] == 3
?
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.
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)
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.
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
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.
Do we actually support non-square kernels?
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.
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.
Closed by #30 |
In this PR, the situation of an empty kernel is avoided and #23 is fixed. The variable
shape
is renamed askernel_size
to avoid confusion with another variablekernel_shape
and the Python command.shape
.