kornia-rs
kornia-rs copied to clipboard
implement `warp_affine` / `warp_perspective`
reference:
- [x] warp_affine: https://github.com/kornia/kornia/blob/main/kornia/geometry/transform/imgwarp.py#L131
- [ ] warp_perspective: https://github.com/kornia/kornia/blob/main/kornia/geometry/transform/imgwarp.py#L48
needs (to abstract / reuse code)
- [ ] grid_sample / map_coordinates
I recently had to implement warp_affine from scratch in Dart to do image transformation in Flutter without OpenCV. I could contribute warp_affine here if you are okay with that. It's probably not gonna be super fast.
grid_sample is not needed. The current bilinear_interpolation()
function should be enough.
feel free to go for it -- about grid_sample, it will basically a way to reuse code. If you see in the resize_native function the ndarray::Zip
is basically parallelizing over the destination points. In any case you will have to reimplement that to make it efficient, we don't want regular looping but instead iterators (which is what's happening in that code already.
Interesting. Do you have benchmarks between naive for-loop version and the current version?
Some observations
- Currently we materialize the whole index array (width x height). This is quite wasteful.
- There is probably overhead for parallelization (from what I see, ndarray uses rayon https://docs.rs/ndarray/latest/ndarray/parallel/index.html). Perhaps we can parallelize over the rows only instead of all the points to reduce overhead.
In any case, let's get a working implementation first before looking more into the speed.
done