-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
The Affine transform currently does not have an affine matrix parameter #3313
Comments
Hi @Spenhouet , Thanks for your feedback. Thanks in advance. |
Sure I feel it might be simpler to have a warp function instead of transform class (unless we cache the grid for performance) |
Hi @wyli , I think maybe we can just add an arg Thanks. |
I don't know what's the benefit here, there's not much benefit compared with "affine.resampler(img, affine.affinegrid(affine)[0])" unless we have additional caching capability |
Hi @wyli , I think maybe @Spenhouet 's request is to set a fixed Thanks. |
Yes, I also do not see the harm of adding this parameter. @wyli or what is your worry? It would also enable to easily perform the inverse operation in the chain. We have a transform which currently contains these lines: projection = np.linalg.inv(target_affine) @ affine
transform = Affine(affine=projection[:3, :3], mode=self.mode)
transformed_matrix: torch.Tensor
transformed_matrix, _ = transform(img.squeeze(0)) Sure, we could also do this: projection = np.linalg.inv(target_affine) @ affine
transform = Affine(mode=self.mode)
transformed_matrix: torch.Tensor
transformed_matrix = transform.resampler(img.squeeze(0), transform.affinegrid(projection[:3, :3])[0]) But compared to simply adding the additional parameter, I don't think this is a great way to solve this. |
We don't normally compose the array transforms. also, if we follow this pattern we'll build complicated transforms with many input arguments and if-else branches, then we lose the readability. |
@wyli Maybe I misunderstood. We are not using the method to apply a static Affine in the pipeline. I get where you are coming from, but I wonder if this is the right case to focus on this. I don't think it will make the Affine transform any more complicated. EDIT: But it will make other methods which use this Affine transform simpler. So we save on complexity there. EDIT2: Or how would you rate the code complexity on these two code snippets: transform = Affine(affine=projection[:3, :3], mode=self.mode)
transformed_matrix, _ = transform(img.squeeze(0)) vs. transform = Affine(mode=self.mode)
transformed_matrix = transform.resampler(img.squeeze(0), transform.affinegrid(projection[:3, :3])[0]) EDIT3: Also the first one will also output the resulting affine while the second will not and will need additional code (further increasing code complexity and boilerplate). |
Signed-off-by: Sebastian Penhouet <s.penhouet@outlook.de>
Signed-off-by: Sebastian Penhouet <sebastian.penhouet@airamed.de>
Is your feature request related to a problem? Please describe.
The
Affine
transform forwards its parameters to theAffineGrid
class.But it currently does not provide the "affine" parameter which the
AffineGrid
class also has.This allows to directly define a affine transformation matrix instead of individual parameters for transformations like rotation.
If computations are directly done with affine transformation matrices, this parameter is really helpful (necessary).
Describe the solution you'd like
The only change necessary, is to add the
affine
parameter and to forward it to theAffineGrid
class.Describe alternatives you've considered
We patched the affine transform locally.
The text was updated successfully, but these errors were encountered: