def warp3d(img, patch_size, rot=0, shear=0, scale=(1, 1, 1), stretch=(0, 0, 0, 0), twist=0): return warp3dFast(img, patch_size, rot, shear, scale, stretch, twist)
def warp3dJoint(img, lab, patch_size, rot=0, shear=0, scale=(1, 1, 1), stretch=(0, 0, 0, 0), twist=0): """ 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 4-dimensional (z,ch,x,y) and larger/equal the patch size lab: array Label data (with offsets subtracted) patch_size: 3-tuple Patch size *excluding* channel for the image: (pz, 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 - X stretching depending on Z - Y stretching depending on Z twist: float Dependence of the rotation angle on z in deg from center to outer border Returns ------- img, lab: np.ndarrays Warped image and labels (cropped to patch_size) """ if len(lab.shape) == 3: lab = _warp3dFastLab(lab, patch_size, np.array(img.shape)[[0, 2, 3]], rot, shear, scale, stretch, twist) img = warp3dFast(img, patch_size, rot, shear, scale, stretch, twist) return img, lab
plt.figure() plt.subplot(121) plt.imshow(test_img, interpolation='none', cmap='gray') plt.subplot(122) plt.imshow(out2[0], interpolation='none', cmap='gray') if False: img_s = maketestimage((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)) if False: img_s = maketestimage((110, 110)) img_s = np.concatenate((img_s[None], ) * 4, axis=0) img_s = np.concatenate((img_s[None], np.exp(img_s[None])), axis=0) out = warp3dFast(img_s, (4, 110, 110), 0, 0, (1, 1, 1), (0.0, 0.0, 0.0, 0.0), 10) if False: # visual 3d n = 100 img_s = np.tile(test_img, n) img_s = img_s.reshape((s1, n, s2)) img_s = np.swapaxes(img_s, 1, 0) patch_size = img_s.shape off = 0 lab = img_s[off:-off, off:-off, off:-off] img = np.concatenate((test_img[None], np.exp(test_img[None])), axis=0) img1, lab1 = warpAugment(img_s[None], lab, patch_size=patch_size)