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

For equate_images, crop only when it is necessary. #446

Closed
LuisOlivaresJ opened this issue May 16, 2023 · 4 comments
Closed

For equate_images, crop only when it is necessary. #446

LuisOlivaresJ opened this issue May 16, 2023 · 4 comments

Comments

@LuisOlivaresJ
Copy link
Contributor

LuisOlivaresJ commented May 16, 2023

I am using pylinac 3.11.0

Describe the bug
I have a bug (ZeroDivisionError) when I use equate_images for two images that actually have the same physical size but different resolution.

To Reproduce

from pylinac.core.image import equate_images
from pylinac.core.image import load
import numpy as np

image1 = load(np.random.rand(20, 20), dpi = 10)
image2 = load(np.random.rand(10, 10), dpi = 5)

I1, I2 = equate_images(image1, image2)

Captura

Expected behavior
I2.shape to be (20,20)

Additional context
The problem begins with the crop method.

img.crop(pixel_width_diff, edges=("left", "right"))

It is called even if pixel_height_diff == 0. In other words, when crop is called with the parameter pixels = 0, the method gives unwanted results.

Proposed solution
Crop method should be called only when pixel_width_diff > 0

I'll make a pull request for this.

@LuisOlivaresJ
Copy link
Contributor Author

LuisOlivaresJ commented May 16, 2023

I have added a proposition inside commit #445.

LuisOlivaresJ added a commit to LuisOlivaresJ/pylinac that referenced this issue May 30, 2023
Regarding issue jrkerns#446

Call crop method only when pixel_difference > 0.
@jrkerns
Copy link
Owner

jrkerns commented Jun 8, 2023

Thanks for the find and the fix. It also appears that the crop method needs to be updated. E.g. doing img.crop(pixels=0, ...) will set the array shape to 0 which is unintended behavior.

I will change this line to be <= 0:

if pixels < 0:

@LuisOlivaresJ
Copy link
Contributor Author

Thanks. This issue could be closed if you want.

@jrkerns
Copy link
Owner

jrkerns commented Aug 15, 2023

Closing. Thanks for the contribution.

@jrkerns jrkerns closed this as completed Aug 15, 2023
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

No branches or pull requests

2 participants