def test_interp_bilinear(self): x = np.mgrid[:10, :10].sum(axis=0) out = ext.interp_bilinear(x, [[1, 2], [1.5, 1.5]], [[2, 1], [1.5, 1.5]]) assert_equal(out, [[3, 3], [3, 3]])
def logpolar(image, angles=None, Rs=None, mode='M', cval=0, output=None, _coords_r=None, _coords_c=None, extra_info=False): """Perform the log polar transform on an image. Input: ------ image : MxNxC array An MxN image with C colour bands. Rs : int Number of samples in the radial direction. angles : 1D array of floats Angles at which to evaluate. Defaults to 0..2*Pi in 4*Rs steps ([1] below suggests 8*Rs, but that causes too much oversampling). mode : string How values outside borders are handled. 'C' for constant, 'M' for mirror and 'W' for wrap. cval : int or float Used in conjunction with mode 'C', the value outside the border. extra_info : bool Whether to return the angles and log base in addition to the transform. False by default. Returns ------- lpt : ndarray of uint8 Log polar transform of the input image. angles : ndarray of float Angles used. Only returned if `extra_info` is set to True. log_base : int Log base used. Only returned if `extra_info` is set to True. Optimisation parameters: ------------------------ _coords_r, _coords_c : 2D array Pre-calculated coords, as given by _lpcoords. References ---------- .. [1] Matungka, Zheng and Ewing, "Image Registration Using Adaptive Polar Transform". IEEE Transactions on Image Processing, Vol. 18, No. 10, October 2009. """ if image.ndim < 2 or image.ndim > 3: raise ValueError("Input image must be 2 or 3 dimensional.") image = np.atleast_3d(image) if Rs is None: Rs = max(image.shape[:2]) if _coords_r is None or _coords_c is None: _coords_r, _coords_c, angles, log_base = \ _lpcoords(image.shape, Rs, angles) bands = image.shape[2] if output is None: output = np.empty(_coords_r.shape + (bands,),dtype=np.uint8) else: output = np.atleast_3d(np.ascontiguousarray(output)) for band in range(bands): output[...,band] = interp_bilinear(image[...,band], _coords_r,_coords_c,mode=mode, cval=cval,output=output[...,band]) output = output.squeeze() if extra_info: return output, angles, log_base else: return output