Пример #1
0
def warp3dLab(lab,
              patch_size,
              size,
              rot=0,
              shear=0,
              scale=(1, 1, 1),
              stretch=(0, 0, 0, 0),
              twist=0):
    return _warp3dFastLab(lab, patch_size, size, rot, shear, scale, stretch,
                          twist)
Пример #2
0
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
Пример #3
0
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
Пример #4
0
        for i in xrange(lab1.shape[0]):
            plt.imsave('/tmp/%i-lab.png' % (i + off), lab1[i, :, :])

    if False:  # visual 3d
        n = 40
        img_s = np.tile(test_img, n)
        img_s = img_s.reshape((s1, n, s2))
        img_s = np.swapaxes(img_s, 1, 2)

        wow1 = warp3dFast(img_s[None], (s1, s2, n), 0, 0, (1, 1, 1),
                          (0.1, 0.1, 0.1, -0.1), 10)
        for i in xrange(n):
            plt.imsave('/tmp/%i-ref.png' % i, wow1[:, :, i] / 255)

        wow2 = _warp3dFastLab(img_s[20:-20, 20:-20], (s1 - 40, s2 - 40, n),
                              (s1, s2, n), 0, 0, (1, 1, 1),
                              (0.1, 0.1, 0.1, -0.1), 10)
        for i in xrange(wow2.shape[2]):
            plt.imsave('/tmp/%i.png' % i, wow2[:, :, i] / 255)

    if False:  # 3d timing
        s = 400
        test = np.random.rand(s, s, s).astype(np.float32)
        test2 = np.random.rand(s * 2, s * 2, s * 2).astype(np.float32)
        t0 = time.time()
        wow1 = warp3dFast(test[None], (s, s, s), 20, 5, (1, 1, 1),
                          (0.1, 0.1, 0.1, 0.1), 10)
        #wow1 = warp3dFast(test[None], (s,s,s))
        print time.time() - t0
Пример #5
0
        for i in xrange(n):
            plt.imsave('/tmp/%i-img.png' % i, img1[0, i, :, :] / 255)

        for i in xrange(lab1.shape[0]):
            plt.imsave('/tmp/%i-lab.png' % (i + off), lab1[i, :, :])

    if False:  # visual 3d
        n = 40
        img_s = np.tile(test_img, n)
        img_s = img_s.reshape((s1, n, s2))
        img_s = np.swapaxes(img_s, 1, 2)

        wow1 = warp3dFast(img_s[None], (s1, s2, n), 0, 0, (1, 1, 1),
                          (0.1, 0.1, 0.1, -0.1), 10)
        for i in xrange(n):
            plt.imsave('/tmp/%i-ref.png' % i, wow1[:, :, i] / 255)

        wow2 = _warp3dFastLab(img_s[20:-20, 20:-20], (s1 - 40, s2 - 40, n),
                              (s1, s2, n), 0, 0, (1, 1, 1), (0.1, 0.1, 0.1, -0.1), 10)
        for i in xrange(wow2.shape[2]):
            plt.imsave('/tmp/%i.png' % i, wow2[:, :, i] / 255)

    if False:  # 3d timing
        s = 400
        test = np.random.rand(s, s, s).astype(np.float32)
        test2 = np.random.rand(s * 2, s * 2, s * 2).astype(np.float32)
        t0 = time.time()
        wow1 = warp3dFast(test[None], (s, s, s), 20, 5, (1, 1, 1), (0.1, 0.1, 0.1, 0.1), 10)
        #wow1 = warp3dFast(test[None], (s,s,s))
        print time.time() - t0