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

Selection of multiple surrounding pixels around a position #737

Closed
felixcremer opened this issue Jun 17, 2024 · 4 comments
Closed

Selection of multiple surrounding pixels around a position #737

felixcremer opened this issue Jun 17, 2024 · 4 comments

Comments

@felixcremer
Copy link
Contributor

With Near I can select the nearest pixel at a given position. Is there an easy way to select multiple pixels surrounding this position.
This is what I came up with:

using DimensionalData
julia> dd = DimArray(rand(6,5), (X(1:6), Y(4:8)))
julia> ypos=6
        ywidth=2
         xpos=3
         xwidth=1
1

julia> ddsub = dd[Y=ypos..(ypos+ywidth*step(dims(dd,Y))), X=xpos..(xpos+xwidth*step(dims(dd,X)))]
kw = Base.Pairs{Symbol, IntervalSets.ClosedInterval{Int64}, Tuple{Symbol, Symbol}, @NamedTuple{Y::IntervalSets.ClosedInterval{Int64}, X::IntervalSets.ClosedInterval{Int64}}}(:Y => 6 .. 8, :X => 3 .. 4)
d1 = Y{IntervalSets.ClosedInterval{Int64}}(6 .. 8)
ds = (X{IntervalSets.ClosedInterval{Int64}}(3 .. 4),)
╭─────────────────────────╮
│ 2×3 DimArray{Float64,2} │
├─────────────────────────┴─────────────────────── dims ┐
   X Sampled{Int64} 3:4 ForwardOrdered Regular Points,
   Y Sampled{Int64} 6:8 ForwardOrdered Regular Points
└───────────────────────────────────────────────────────┘
    6         7         8
 3    0.127596  0.255981  0.347761
 4    0.542776  0.674099  0.19914

This is a bit annoying to writeout and also one has to make sure, that the direction is correct when the stepsize is negative.

@rafaqz
Copy link
Owner

rafaqz commented Jun 17, 2024

Do I have a PR for you...
#717

The idea is to allow Near and At to accept a Tuple{A,B} and return a range in that case. I think that branch should already do what you want with Near(ypos1, ypos2). Although you wont always get the same size range back...

@felixcremer
Copy link
Contributor Author

Nice. I will try to test that PR.

@rafaqz
Copy link
Owner

rafaqz commented Jun 17, 2024

It's possible it will break on reverse lookups 😅

@rafaqz
Copy link
Owner

rafaqz commented Aug 16, 2024

This is merged now

@rafaqz rafaqz closed this as completed Aug 16, 2024
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

No branches or pull requests

2 participants