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

add center/centered helpers #242

Merged
merged 4 commits into from
May 23, 2021
Merged

add center/centered helpers #242

merged 4 commits into from
May 23, 2021

Conversation

johnnychen94
Copy link
Member

closes #169

"""
function center(A::AbstractArray, r::RoundingMode=RoundDown)
map(axes(A)) do inds
round(Int, (length(inds)-1)/2, r) + first(inds)
Copy link
Member Author

@johnnychen94 johnnychen94 May 22, 2021

Choose a reason for hiding this comment

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

The default RoundDown and length(inds)-1 is chosen to match the previous ImageFiltering.centered behavior:

julia> A = reshape(collect(1:6), 2, 3)
2×3 Matrix{Int64}:
 1  3  5
 2  4  6

julia> OffsetArrays.centered(A) == ImageFiltering.centered(A)
true

@codecov
Copy link

codecov bot commented May 22, 2021

Codecov Report

Merging #242 (02fe12e) into master (b189da0) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #242      +/-   ##
==========================================
+ Coverage   95.33%   95.37%   +0.04%     
==========================================
  Files           5        5              
  Lines         407      411       +4     
==========================================
+ Hits          388      392       +4     
  Misses         19       19              
Impacted Files Coverage Δ
src/OffsetArrays.jl 98.21% <100.00%> (+0.02%) ⬆️

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 b189da0...02fe12e. Read the comment docs.

src/OffsetArrays.jl Outdated Show resolved Hide resolved
Sometimes, it will be convenient to shift the center coordinate of the given array to `(0, 0, ...)`,
`OffsetArrays.centered` is a helper for this very purpose:

```@repl index
Copy link
Member

Choose a reason for hiding this comment

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

should these be doctests instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

The doctests are already in the src/ and test/ so I think it's okay to just follow the previous doc format here.

@jishnub
Copy link
Member

jishnub commented May 23, 2021

LGTM

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.

move ImageFiltering.centered here
2 participants