-
Notifications
You must be signed in to change notification settings - Fork 7
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
Cleanup DisplacementField #31
Conversation
@Stannislav @EmilieDel Feel free to check it out:) Btw I had to fork since I do not have the rights to push to remote. Also, I do not have the rights to assign reviewers:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for doing this cleaning @jankrepl ! I like the plot_dvf
method but it is maybe better to keep this DisplacementField
class minimal!
I suggest we can always create a separate module Also, as discussed many times IMO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for the cleaning!
I totally agree that matplotlib
should only ever be imported in one module, namely in a dedicated visualisation
/ plot
/ whatever module. So while we can think about keeping the plotting routines I definitely think they're better off in a separate module instead of the DisplacementField
class.
I used a very similar plot_dvf
function in my notebooks, but the arguments of quiver
were slightly different:
def plot_dvf(dvf, ax, n_skip=1):
dx, dy = dvf[:, ::n_skip, ::n_skip]
lengths = np.hypot(dx, dy)
ax.quiver(dx, dy, lengths, cmap="binary")
maybe this is helpful. Probably one should still call ax.invert_yaxis()
though.
A small note, mabe this can be done here as a "while I'm at it": in the norm
proprty I think we could use the np.hypot
function, which is made exactly for computing this kind of things.
Wow, never heard of |
I hope that it is faster, but I haven't tested... |
I created an issue for this #45 Anyway, could one of you guys merge this branch into |
Closes #9
What was kept
__init__
- constructs the instance using twonumpy
arrays(dx, dy)
__eq__
- checking equality - usesnp.allclose
with default parameters__mul__
- multiplying by a constant (mainly for visualization[(c * df).warp(img) for c in np.linspace(0, 1)]
)__rmul__
- see__mul__
from_file
- one can load a DF from a.npy
lying on the diskfrom_transformation
- Creating an instance via(tx, ty)
(rather than(dx, dy)
as in the__init__
). Used inwarp
andsync.get_transform
.norm
- Compute norm. Very useful for visualizing since one canplt.imshow(df.norm)
+ one line implementation.save
- Save to disk as a.npy
file. Compatible withfrom_file
.transformation
-(tx, ty)
Actual pixel positions (rather than displacements(dx, dy)
). Used inside ofwarp
.warp
- warpingWhat was removed (together with corresponding tests)
__call__
- composition of 2 fieldsadjust
- "smoothen" a displacement fieldaverage_displacement
- computes the mean norm over all pixelsdelta_x_scaled
,delta_y_scaled
- divides the displacements by the height (resp. width)generate
- DF generating, note thataffine
andaffine_simple
are still accessible via standalone functionsjacobian
- estimates jacobian for each pixel (gives info on smoothness)is_valid
- checking whether all elements ofdelta_x
anddelta_y
are finitemask
- masking chosen pixels to have 0 displacementn_pixels
- counts the number of pixelsoutsiders
- for each pixels determines whether it is mapped outside of the imageplot_dvf
- plot displacement vector fieldplot_outside
- plots theoutsiders
plot_ranges
- plot domain and the range of the mappingresize
- resizing a displacement fieldresize_constant
- resizing (another way) a displacement fieldwarp_annotation
- warping with nearest neighbors interpolation. One can simply callwarp(interpolation="nearest")
insteadRandom comments
DisplacementField
is just a very thin wrapper around OpenCV'sremap
. Of course there is always a possibility of switching to a different backend in the future.matplotlib
inside ofatldld/base.py
pytest -m "" --cov-report=term-missing
---------- coverage: platform darwin, python 3.8.11-final-0 ---------- Name Stmts Miss Branch BrPart Cover Missing -------------------------------------------------------------------- src/atldld/__init__.py 2 0 0 0 100% src/atldld/base.py 101 0 32 0 100% src/atldld/cli.py 20 20 2 0 0% 17-61 src/atldld/sync.py 168 62 60 9 58% 61, 108, 125, 293, 398, 401, 411-416, 503-520, 605->607, 614, 656-698, 745-789 src/atldld/utils.py 116 25 46 5 74% 57, 110, 121, 126-139, 500, 520-540 src/atldld/version.py 1 0 0 0 100% -------------------------------------------------------------------- TOTAL 408 107 140 14 71%