Hi Johannes, Spot on - I was indeed computing the output_shape as a tuple of floats rather than integers, and casting them to ints fixed the problem. I'm a bit surprised it actually worked in v0.7.1! Cheers, Alistair On Sunday, July 21, 2013 10:17:14 PM UTC+1, Johannes Schönberger wrote:
Hi,
does the **kwargs contain the output_shape?
Make sure that the the values are integers: `output_shape = (int(rows), int(cols))`.
Johannes Schönberger
Am 21.07.2013 um 17:20 schrieb Alistair Muldal <alim...@gmail.com<javascript:>>:
Hi all,
I've been using skimage.transform.warp to apply affine transformations to a series of movie frames, using this wrapper function:
def applytform(img,tmat,**kwargs): """ A wrapper to call skimage.transform.warp for fast similarity transformations. Also returns the mask of the transformed image (a boolean array, True only in pixels containing the transformed image). All keyword arguments are passed directly to warp. """
# warp needs floating point images -1.0 <= I <= 1.0 origtype, imin, imax = img.dtype, img.min(), img.max() tmpimg = (np.float64(img) - imin) / (imax-imin)
# tmpimg = np.require(tmpimg,np.float32,'CAOW') # tmat = np.require(tmat,np.float32,'CAOW')
# construct a callable transform object, apply it using warp s = SimilarityTransform(matrix=tmat) # import ipdb;ipdb.set_trace() tmpimg = warp(tmpimg,s.inverse,mode='constant',cval=np.nan,**kwargs) mask = ~np.isnan(tmpimg) tmpimg[~mask] = 0.
# convert back to original scaling and type img = tmpimg*imax + imin img = img.astype(origtype)
return img,mask
I've had no problems using skimage v0.7.1, but I've recently tried updating to v0.8.2 and now the same code gives me this error:
/home/alistair/src/python/ca_tadpoles2/opt/d/imtransform3.pyc in applytform(img, tmat, **kwar gs) 50 s = SimilarityTransform(matrix=tmat) 51 # import ipdb;ipdb.set_trace() ---> 52 tmpimg = warp(tmpimg,s.inverse,mode='constant',cval=np.nan,**kwargs) 53 mask = ~np.isnan(tmpimg) 54 tmpimg[~mask] = 0.
/home/alistair/.venvs/newskimage/lib/python2.7/site-packages/skimage/transform/_geometric.pyc
in warp(image, inverse_map, map_args, output_shape, order, mode, cval, reverse_map) 989 dims.append(_warp_fast(image[..., dim], matrix, 990 output_shape=output_shape, --> 991 order=order, mode=mode, cval=cval)) 992 out = np.dstack(dims) 993 if orig_ndim == 2:
/home/alistair/.venvs/newskimage/lib/python2.7/site-packages/skimage/transform/_warps_cy.so i
n skimage.transform._warps_cy._warp_fast (skimage/transform/_warps_cy.c:1636)()
TypeError: 'numpy.float64' object cannot be interpreted as an index
I've tried casting the image and the transformation matrix to np.float32, but this gave me a different error:
/home/alistair/src/python/ca_tadpoles2/opt/d/imtransform3.pyc in applytform(img, tmat, **kwargs) 50 s = SimilarityTransform(matrix=tmat) 51 # import ipdb;ipdb.set_trace() ---> 52 tmpimg = warp(tmpimg,s.inverse,mode='constant',cval=np.nan,**kwargs) 53 mask = ~np.isnan(tmpimg) 54 tmpimg[~mask] = 0.
/home/alistair/.venvs/newskimage/lib/python2.7/site-packages/skimage/transform/_geometric.pyc in warp(image, inverse_map, map_args, output_shape, order, mode, cval, reverse_map)
989 dims.append(_warp_fast(image[..., dim], matrix, 990 output_shape=output_shape, --> 991 order=order, mode=mode, cval=cval)) 992 out = np.dstack(dims) 993 if orig_ndim == 2:
/home/alistair/.venvs/newskimage/lib/python2.7/site-packages/skimage/transform/_warps_cy.so in skimage.transform._warps_cy._warp_fast (skimage/transform/_warps_cy.c:1505)()
ValueError: Buffer dtype mismatch, expected 'double_t' but got 'float'
Any idea what's going on here?
-- You received this message because you are subscribed to the Google
Groups "scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com <javascript:>. For more options, visit https://groups.google.com/groups/opt_out.