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

Make Flips ND compatible and fix ND ScaleKeepAspect, ScaleFixed and PinOrigin #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

itan1
Copy link
Contributor

@itan1 itan1 commented Jan 3, 2023

  • Updated some of the projective transform functions such that they are ND compatible (ScaleKeepAspect, ScaleFixed, PinOrigin)
  • Added a generic ND compatible FlipDim and made FlipX FlipY and FlipZ aliases
  • Added those transformations to the 3D test case in test/projective/affine.jl

The transforms Rotate and Reflect are still only 2D compatible.

closes #74

…ed and PinOrigin. Also add ScaleFixed and Zoom to the 3D test to catch the bug.
Copy link
Member

@lorenzoh lorenzoh left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

This looks good generally, I've left some comments. It seems that this only touches Flip, not Zoom like the title implies, right?

Other than the minor suggested changes, could you add some tests that test that these transformations behave correctly in 3D? Some sanity checks, i.e.

  • FlipX{3}() applied to a (10, 10, 1) image should be the same as FlipX{2}() to a (10, 10) image (dropping the last dimension). Same for FlipY
  • FlipZ{3}() applied to a (10, 10, 1) image should be an identity operation

If you're testing this on 3D images, I would also be interested in some visual examples as an additional check. Let me know if you something is unclear!

function reflectionmatrix(r)
A = SMatrix{2, 2, Float32}(cos(2r), sin(2r), sin(2r), -cos(2r))
return round.(A; digits = 12)
end


"""
FlipDim{N}()
Copy link
Member

Choose a reason for hiding this comment

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

Think this should be

Suggested change
FlipDim{N}()
FlipDim{N}(dim)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 208 to 210
FlipX(N) = FlipDim{N}(N==2 ? 2 : 1)
FlipY(N) = FlipDim{N}(N==2 ? 1 : 2)
FlipZ(N) = FlipDim{N}(3)
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this so you call FlipX{N}()? The way it is I find it somewhat confusing that for FlipDim the type variable is the dimension of the data, where as for FlipXYZ the dimension of the data is the argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes makes sense, I changed it accordingly

@itan1
Copy link
Contributor Author

itan1 commented Jan 11, 2023

Thank you for the feedback :)

Yes you're right, Zoom is not affected. Only Flip is added and I fixed a small bug in ScaleFixed, ScaleKeepAspect and PinOrigin.

I just added 2 tests for images where the flip dimension has size 1, but I ran into a BoundsError in Interpolations.jl. Applying the flip transform fails, both for 2D and 3D. I could not reproduce the error in the REPL but apparently during tests Julia always uses bounds checking. That explains why it only occurs in the tests. I haven't found the exact reason yet but will have another look.

@itan1 itan1 changed the title Make flip and zoom nd compatible Make Flips ND compatible and fix ND ScaleKeepAspect, ScaleFixed and PinOrigin Jan 11, 2023
@itan1
Copy link
Contributor Author

itan1 commented Mar 6, 2023

The arrays with singleton dimensions did not work well with Interpolations.jl, they give bounds errors during testing.

Instead of the singleton tests I checked the flipped image pixel values by reverse indexing and added a test to check that double flipping results in the original image.

@CarloLucibello
Copy link
Member

@lorenzoh can this be merged?

@paulnovo
Copy link
Contributor

I merged master into this branch and updated a few things in this branch. I can help with any additional needed changes to get this merged. If everything looks good, should I create a PR into this itan1 branch? Or a new PR into FluxML/Data augmentation.jl?

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.

FlipX, FlipY and ScaleFixed are not ND compatible
4 participants