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

bug in rotation part of tio.transforms.RandomAffine #1126

Closed
1 task done
javidsss opened this issue Nov 21, 2023 · 4 comments
Closed
1 task done

bug in rotation part of tio.transforms.RandomAffine #1126

javidsss opened this issue Nov 21, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@javidsss
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Bug summary

I experimented with various "degrees" values in tio.transforms.RandomAffine, and found that I randomly get empty images. Overall, due to the nature of rotation transformation, I expected some inconsistencies between different runs, but not getting completely zero images.

Code for reproduction

for i in range(20):
    transform_rotate = tio.transforms.RandomAffine(degrees=(0,0,0,0,5,5), p=1) # I experimented with degrees=(0,0,0,0,5,10), etc.
    torchio_image_rotate = transform_rotate(torchio_image)
    plt.figure()
    plt.imshow(torchio_image_rotate.data[0, :, :, 1], cmap='gray') #torchio_image_rotate shape: torch.Size([1, 224, 224, 48])

Actual outcome

Out of 20 images, maybe around 13-14 of them look very similar to each other and are the correct rotated images by around 5 degrees, however, about 6-7 of the output images are just zeros

Error messages

No error, the outcome is not correct

Expected outcome

I expected about 20 images relatively similar to each other. They should be about 5 degrees rotated with respect to their last axis

System info

No response

@javidsss javidsss added the bug Something isn't working label Nov 21, 2023
@romainVala
Copy link
Contributor

Hi
sound weird, I suspect it comes from your images
but try with
transform_rotate = tio.transforms.RandomAffine(degrees=(0,0,0,0,5,5), p=1, scale=0)
by default scaling factor is 0.1

@fepegar
Copy link
Owner

fepegar commented Nov 23, 2023

@javidsss, can you please share some data, a minimal working example and screenshots?

@fepegar
Copy link
Owner

fepegar commented Nov 23, 2023

By the way, you are showing the top slice, which will probably be black if you are looking, for example, at an MRI in RAS orientation:

torchio_image_rotate.data[0, :, :, 1]

For example:

In [1]: import torchio as tio

In [2]: t1 = tio.datasets.FPG().t1

In [3]: import matplotlib.pyplot as plt

In [4]: plt.imshow(t1.data[0, :, :, 1], cmap='gray')
Installed osx event loop hook.
Out[4]: <matplotlib.image.AxesImage object at 0x16c7cc950>

In [5]: plt.show()

Figure_1

You can use the plot method instead:

In [6]: t1.plot()

Figure_1

I'm going to assume that it's simply a visualization issue and not a bug. Feel free to reopen if you disagree.

@fepegar fepegar closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2023
@javidsss
Copy link
Author

Thank you all for your help. The trick with adding scales=0 solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants