0

I am looking for a Python image processing package that will allow me to take a source image, and to create a new image by specifying a pixel location to take each pixel in the source image to, on a pixel-by-pixel basis (i.e. more general than an affine transformation). Specifically, if the original image is a 2-d array A, and we have an array of x-coordinates (indices of A) X and an array of y-coordinates (indices of A) Y, then an each element of Z, Z(i,j) goes to a pixel in the new image A' at (X(i,j),Y(i,j)).

Basically I am trying to do (x,y)->(f(x,y), g(x,y)), but quickly.

Currently I am doing this "by hand" in numpy as a nested loop iterating over pixels in the source image, and I feel certain there is something in a package out there that will do this much more quickly, though I've not found it. Something like cartopy clearly has something of this sort going on to do image transformations.

stuwilmur
  • 112
  • 1
  • 1
  • 7

1 Answers1

0

After some research I discovered this is possible with OpenCV using remap. However, remap solves the inverse problem, i.e. for every pixel in the destination image, a pixel location is specified at which to sample the source image. I merely needed to invert my problem.

This answer on Stack Overflow is a good starting point.

stuwilmur
  • 112
  • 1
  • 1
  • 7
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 23 '21 at 03:12
  • I'm not sure I could improve this much further without adding further examples: answer includes both a link to the documentation and an example. Happy to add something else specific if required. – stuwilmur Oct 28 '21 at 09:11