Hi all! I tried to post this to the extant thread 'getting hsi to work with numpy', but it seems to have been closed. So here is the continuation:
I have not been idle, and to all who may be interested I can give a brief summary of what I have done. My reason for introducing numpy access to hsi was to communicate numpy arrays to and fro hsi to transport bulk transformation data. The idea was to calculate a matrix of PT-transformed coordinates and feed them into a general-purpose remap() function. Initially I worked with a modified libpano which used a vectorized version of execute_stack, but I found that using separate calls to execute_stack from a vectorized C- routine inside the python interface was just about as efficient, so I binned the vectorized libpano code in favour of just one modified file, an adapted version of hsi.i. Integrating numpy was relatively easy once I had obtained and understood the relevant code. The crucial part is a file called numpy.i, which can be obtained from https://github.com/numpy/numpy/blob/master/doc/swig/numpy.i It has code for the relevant typemaps, and I could take it from there, resulting in an a modified version of hsi.i: http://bazaar.launchpad.net/~kfj/+junk/script/view/head:/main/hsi.i This version of the python module has a routine to handle bulk transformations, which is much faster than calling individual transforms from a loop in python. The code can now be used like this: ######### begin code snippet import hsi import numpy as np # get_tf_matrix takes two linspace parameter sets and sets up a grid # of panorama coordinates with them. The vectorized PT transform is # used to convert the whole arrays to image coordinates. The resulting # coordinates are returned. def get_tf_matrix ( x0, x1, xn, y0, y1, yn , tf ) : xv = np.linspace ( x0 , x1 , xn ) yv = np.linspace ( y0 , y1 , yn ) # make a mesh grid from these x and y values xx , yy = np.meshgrid ( xv , yv ) # the PT routine is made to operate in-place, so the # pano coordinate arrays are overwritten with the # image coordinate arrays. # PT needs flattened coordinate vectors. tfx = xx.flatten() tfy = yy.flatten() # here's the call to the new vectorized transform: success = tf.transform ( tfx , tfy , tfx , tfy ) return tfx , tfy # let's use it: # assume pano refers to an hsi.Panorama object pano_options = pano.getOptions() # we create transforms from pano coordinates to image coordinates tf = hsi.Transform() tf.createTransform ( args.image , pano_options ) tfx, tfy = get_tf_matrix ( 0, 100, 1024, 0, 100, 1024 , tf ) ########## End of code snippet In case you're curious, this is from an experimental nona work-alike I've written in python using vigranumpy, openCV and hsi, and which I haven't published yet because I'd like to do some stuff I currently use openCV for with vigranumpy instead, but I haven't yet managed to come up with fast-enough code in vigranumpy - the vigra mailing list has the story. If anyone wants to use the modified hsi.i, they will need above- mentioned file numpy.i as well, and they will need the appropriate numpy environment, since numpy.i relies on a few numpy headers being in place. On a Linux system, this should be easy to obtain - I use Kubuntu 11.4 and all I needed was in the regular packets for my distro. Your mileage on unfree systems may vary. Including numpy.i and requiring numpy dev capability is adding yet more dependencies, but I feel there would be a considerable gain, twofold: - the vectorized PT transform decouples the transformation from the remapping. Thus, I was able to use interpolation methods PT doesn't offer. Experimentation along these lines is now very easy, and it doesn't cost performance, since the actual number-crunching is still done by C code. Using extant libraries makes the whole approach rather covenient. - having written an interface from the PT transform to numpy, I've demonstrated the technique, so that it may be used for other bulk data. My use of numpy.i in hsi.i can serve as a template. I'd welcome comments, and I wonder if the advantages are sufficient to introduce these additions to the mainstream, or if there is a good way to make them optional (I'm not a cmake wizard ;-) Kay -- You received this message because you are subscribed to the Google Groups "Hugin and other free panoramic software" group. A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/hugin-ptx
