kornia-rs icon indicating copy to clipboard operation
kornia-rs copied to clipboard

implement `warp_affine` / `warp_perspective`

Open edgarriba opened this issue 11 months ago • 3 comments

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

edgarriba avatar Mar 12 '24 10:03 edgarriba

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.

gau-nernst avatar Mar 28 '24 14:03 gau-nernst

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.

edgarriba avatar Mar 28 '24 16:03 edgarriba

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.

gau-nernst avatar Mar 28 '24 23:03 gau-nernst

done

edgarriba avatar Jun 17 '24 19:06 edgarriba