def test(): try: img_s = np.random.rand(11, 11) img_s = np.concatenate((img_s[None], np.exp(img_s[None])), axis=0) out = warp2dFast(img_s, (11, 11), 0, 0, (1, 1), (0.0, 0.0)) except Exception as e: print """%s Warping is broken. Most likeley the distributed _warping.so is not binary compatible to your system.""" % (e, )
def warp2dJoint(img, lab, patch_size, rot, shear, scale, stretch): """ Warp image and label data jointly. Non-image labels are ignored i.e. lab must be 3d to be warped Parameters ---------- img: array Image data The array must be 3-dimensional (ch,x,y) and larger/equal the patch size lab: array Label data (with offsets subtracted) patch_size: 2-tuple Patch size *excluding* channel for the image: (px, py). The warping result of the input image is cropped to this size rot: float Rotation angle in deg for rotation around z-axis shear: float Shear angle in deg for shear w.r.t xy-diagonal scale: 3-tuple of float Scale per axis stretch: 4-tuple of float Fraction of perspective stretching from the center (where stretching is always 1) to the outer border of image per axis. The 4 entry correspond to: - X stretching depending on Y - Y stretching depending on X Returns ------- img, lab: np.ndarrays Warped image and labels (cropped to patch_size) """ if len(lab.shape) == 2: lab = _warp2dFastLab(lab, patch_size, img.shape[1:], rot, shear, scale, stretch) img = warp2dFast(img, patch_size, rot, shear, scale, stretch) return img, lab
# s1 = test_img.shape[0] # s2 = test_img.shape[1] ps = (200, 200) if True: ext_size, rot, shear, scale, stretch, twist = getWarpParams(ps, amount=1.0) t = [] for i in xrange(10000): ext_size, rot, shear, scale, stretch, twist = getWarpParams( ps, amount=1.0) t.append(ext_size) # img_in = maketestimage(eff_size) # img_in = paddImage(img_in, ext_size, left_exc)[None] img_in = maketestimage(ext_size)[None] out = warp2dFast(img_in, ps, rot, shear, scale, stretch) plt.figure() plt.subplot(121) plt.imshow(img_in[0], interpolation='none', cmap='gray') plt.hlines(ext_size[0] / 2 - 0.5, 0, ext_size[1] - 1, color='r') plt.vlines(ext_size[1] / 2 - 0.5, 0, ext_size[0] - 1, color='r') plt.subplot(122) plt.imshow(out[0], interpolation='none', cmap='gray') plt.hlines(ps[0] / 2 - 0.5, 0, ps[1] - 1, color='r') plt.vlines(ps[1] / 2 - 0.5, 0, ps[0] - 1, color='r') if False: # visual 2d #out = _warp2d_c(test_img, 20, 10, (1,1.1), (0.1, 0)) test_img = np.concatenate((test_img[None], np.exp(test_img[None])), axis=0)
# test_img = io.imread('Lichtenstein.png') # test_img = test_img.mean(axis=2) # s1 = test_img.shape[0] # s2 = test_img.shape[1] ps = (200, 200) if True: ext_size, rot, shear, scale, stretch, twist = getWarpParams(ps, amount=1.0) t = [] for i in xrange(10000): ext_size, rot, shear, scale, stretch, twist = getWarpParams(ps, amount=1.0); t.append(ext_size) # img_in = maketestimage(eff_size) # img_in = paddImage(img_in, ext_size, left_exc)[None] img_in = maketestimage(ext_size)[None] out = warp2dFast(img_in, ps, rot, shear, scale, stretch) plt.figure() plt.subplot(121) plt.imshow(img_in[0], interpolation='none', cmap='gray') plt.hlines(ext_size[0] / 2 - 0.5, 0, ext_size[1] - 1, color='r') plt.vlines(ext_size[1] / 2 - 0.5, 0, ext_size[0] - 1, color='r') plt.subplot(122) plt.imshow(out[0], interpolation='none', cmap='gray') plt.hlines(ps[0] / 2 - 0.5, 0, ps[1] - 1, color='r') plt.vlines(ps[1] / 2 - 0.5, 0, ps[0] - 1, color='r') if False: # visual 2d #out = _warp2d_c(test_img, 20, 10, (1,1.1), (0.1, 0)) test_img = np.concatenate((test_img[None], np.exp(test_img[None])), axis=0) out2 = warp2dFast(test_img, (512, 512), 20, 10, (1, 1.1), (0.1, 0))