Efficient arbitrary resampling of an array
- To: mathgroup at smc.vnet.net
- Subject: [mg69667] Efficient arbitrary resampling of an array
- From: Gareth Russell <russell at njit.edu>
- Date: Wed, 20 Sep 2006 02:44:26 -0400 (EDT)
- Organization: New Jersey Institute of Technology
Hi Group, Does anyone know how to efficiently run a kernel over an array, but where the kernel is centered arbitrarily instead of exactly on original array elements, and may be of 'non-integer' size? Here's the background/explanation: I need to downsample a 2D array of reals -- an operation similar to reducing the resolution of a grayscale image. The array represents values from a grid of squares. There are two catches. The first is that the grid represented by the original array, and the grid represented by the resampled array, are arbitrarily located relative to one another. Thus each value (grid cell) in the resampled array not only samples more than one cell in the original array, but may sample fractions of various cells. The other catch is that the resampled cells should be accurate weighted means of the original cells that they cover, where the weights are the proportion of each cell in the resampling area. That prevents me using ListInterpolation (which would be easy, and what is often done in image processing). The problem is how to do this efficiently. In my application, the original array might have dimensions of, say, 3000 by 3000, and the resampled array perhaps 200 by 200. So there would be 40,000 new array values, each of which has to be calculated from approximately 225 of the original values (depending on how each new grid cell lies over the old grid cells). The inputs to the function would be resample[array_, arrayCorners_, newArrayCorners_, newArrayResolution_] where arrayCorners is a 2 x 2 list giving the {x,y} coordinates of the lower left and upper right of the original grid, newArrayCorners is the same but for the new resampled grid, and newArrayResolution is a two-element list giving the number of cells in the x and y direction in the new grid. The output would be a new array with dimensions {newArrayResolution[[2]], newArrayResolution[[1]]}. As mentioned above, the kernel should be calculating a weighted mean. A lot of this is bookkeeping, and I can do that, but I'm having trouble creating a fast version of the core routine, which is the 'kernel problem' above. Any help would be appreciated. I'll compile a list of any suggestions and test them all on the same machine for a speed comparison... Gareth Russell Rutgers/NJIT