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

swirl operation #146

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

Conversation

ashwani-rathee
Copy link
Member

@ashwani-rathee ashwani-rathee commented Oct 3, 2021

  • Adds swirl operation in ImageTransformations.jl

Fixes: #133
Doubt:

  • How to write tests for things like this?

@codecov
Copy link

codecov bot commented Oct 3, 2021

Codecov Report

Merging #146 (25c2a95) into master (4d89e5c) will decrease coverage by 18.62%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #146       +/-   ##
===========================================
- Coverage   89.06%   70.44%   -18.63%     
===========================================
  Files           8        9        +1     
  Lines         192      159       -33     
===========================================
- Hits          171      112       -59     
- Misses         21       47       +26     
Impacted Files Coverage Δ
src/ImageTransformations.jl 66.66% <ø> (-16.67%) ⬇️
src/swirl.jl 100.00% <100.00%> (ø)
src/interpolations.jl 40.90% <0.00%> (-31.10%) ⬇️
src/autorange.jl 66.66% <0.00%> (-26.02%) ⬇️
src/resizing.jl 76.31% <0.00%> (-23.69%) ⬇️
src/compat.jl 0.00% <0.00%> (-16.67%) ⬇️
src/warpedview.jl 92.30% <0.00%> (-1.81%) ⬇️
src/warp.jl 100.00% <0.00%> (ø)
src/invwarpedview.jl 84.21% <0.00%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d89e5c...25c2a95. Read the comment docs.

Copy link
Member

@johnnychen94 johnnychen94 left a comment

Choose a reason for hiding this comment

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

Can you also help update the demo with some info comment such as

In this example, we illustrate how to construct a custom warping map and pass it to warp. This swirl example comes from the Princeton Computer Graphics course for Image Warping (Fall 2000) and scikit-image swirl example.
+ To apply the swirl effect, please use the existing `swirl` function in ImageTransformations.jl directly.

How to write tests for things like this?

This is a thin wrapper on the low-level interface warp, so as long as we ensure the arguments are computed and passed correctly, it should be fine. A similar example is imrotate

test/swirl.jl Outdated
Comment on lines 13 to 15
replace!(res, NaN=>0.0)
replace!(expected, NaN=>0.0)
@test isapprox(res, expected; atol=0.1)
Copy link
Member

Choose a reason for hiding this comment

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

There's nearlysame

nearlysame(x, y) = x y || (isnan(x) & isnan(y))
nearlysame(A::AbstractArray, B::AbstractArray) = all(map(nearlysame, A, B))
that can be used here.

Copy link
Member Author

@ashwani-rathee ashwani-rathee Oct 4, 2021

Choose a reason for hiding this comment

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

issue arose mainly from here

julia> expected[2,2]
0.431797

julia> res[2,2]
0.4317972472093078

julia> res[2,2] ≈ expected[2,2]
false

Copy link
Member Author

Choose a reason for hiding this comment

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

nearlysame(x, y, atol = 0.0) = isapprox(x, y; atol = atol) || (isnan(x) & isnan(y))
nearlysame(A::AbstractArray, B::AbstractArray; atol = 0.0) = all(map((a,b,atol)-> nearlysame(a, b, atol), A, B, atol))

I think this would be better

src/swirl.jl Outdated Show resolved Hide resolved
src/swirl.jl Outdated Show resolved Hide resolved
src/swirl.jl Outdated Show resolved Hide resolved
src/swirl.jl Outdated Show resolved Hide resolved
test/swirl.jl Show resolved Hide resolved
Comment on lines +2 to +6
img = [0 0 0 0 0
0 0 1 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 0 0]
Copy link
Member

Choose a reason for hiding this comment

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

I think we would also want to test OffsetArrays and Gray/RGB images.

@johnnychen94 johnnychen94 mentioned this pull request Oct 3, 2021
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.

add swirl function
2 participants