當前位置: 首頁>>代碼示例>>Python>>正文


Python ndimage.affine_transform方法代碼示例

本文整理匯總了Python中scipy.ndimage.affine_transform方法的典型用法代碼示例。如果您正苦於以下問題:Python ndimage.affine_transform方法的具體用法?Python ndimage.affine_transform怎麽用?Python ndimage.affine_transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.affine_transform方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: affine_transform

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def affine_transform(image, affine_value):
    shape = image.shape
    alpha_affine = min(shape[0], shape[1]) * affine_value
    random_state = np.random.RandomState(None)
    # Random affine
    shape_size = shape[:2]
    center_square = np.float32(shape_size) // 2
    square_size = min(shape_size) // 3
    pts1 = np.float32(
        [center_square + square_size, [center_square[0] + square_size, center_square[1] - square_size],
         center_square - square_size])
    pts2 = pts1 + random_state.uniform(-alpha_affine, alpha_affine, size=pts1.shape).astype(np.float32)
    M = calcAffineMatrix(pts1, pts2)
    R = M[0:2, 0:2]
    Off = M[:, 2]
    for aD in range(shape[2]):
        image[:, :, aD] = scipy_affine_transform(image[:, :, aD], R, offset=Off)
    return image 
開發者ID:TobiasGruening,項目名稱:ARU-Net,代碼行數:20,代碼來源:util.py

示例2: test_affine_transform09

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform09(self):
        data = numpy.array([[4, 1, 3, 2],
                               [7, 6, 8, 5],
                               [3, 5, 3, 6]])
        for order in range(0, 6):
            if (order > 1):
                filtered = ndimage.spline_filter(data,
                                                           order=order)
            else:
                filtered = data
            out = ndimage.affine_transform(filtered,[[1, 0],
                                                               [0, 1]],
                                  [-1, -1], order=order, prefilter=False)
            assert_array_almost_equal(out, [[0, 0, 0, 0],
                                       [0, 4, 1, 3],
                                       [0, 7, 6, 8]]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_ndimage.py

示例3: test_uint64_max

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_uint64_max():
    # Test interpolation respects uint64 max.  Reported to fail at least on
    # win32 (due to the 32 bit visual C compiler using signed int64 when
    # converting between uint64 to double) and Debian on s390x.
    # Interpolation is always done in double precision floating point, so we
    # use the largest uint64 value for which int(float(big)) still fits in
    # a uint64.
    big = 2**64-1025
    arr = np.array([big, big, big], dtype=np.uint64)
    # Tests geometric transform (map_coordinates, affine_transform)
    inds = np.indices(arr.shape) - 0.1
    x = ndimage.map_coordinates(arr, inds)
    assert_equal(x[1], int(float(big)))
    assert_equal(x[2], int(float(big)))
    # Tests zoom / shift
    x = ndimage.shift(arr, 0.1)
    assert_equal(x[1], int(float(big)))
    assert_equal(x[2], int(float(big))) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:20,代碼來源:test_datatypes.py

示例4: test_affine_transform26

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform26(self):
        # test homogeneous coordinates
        data = numpy.array([[4, 1, 3, 2],
                            [7, 6, 8, 5],
                            [3, 5, 3, 6]])
        for order in range(0, 6):
            if (order > 1):
                filtered = ndimage.spline_filter(data, order=order)
            else:
                filtered = data
            tform_original = numpy.eye(2)
            offset_original = -numpy.ones((2, 1))
            tform_h1 = numpy.hstack((tform_original, offset_original))
            tform_h2 = numpy.vstack((tform_h1, [[0, 0, 1]]))
            out1 = ndimage.affine_transform(filtered, tform_original,
                                            offset_original.ravel(),
                                            order=order, prefilter=False)
            out2 = ndimage.affine_transform(filtered, tform_h1, order=order,
                                            prefilter=False)
            out3 = ndimage.affine_transform(filtered, tform_h2, order=order,
                                            prefilter=False)
            for out in [out1, out2, out3]:
                assert_array_almost_equal(out, [[0, 0, 0, 0],
                                                [0, 4, 1, 3],
                                                [0, 7, 6, 8]]) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:27,代碼來源:test_ndimage.py

示例5: map_image

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def map_image(img, out_affine, out_shape, ras2ras=np.array([[1.0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]),
              order=1):
    """
    Function to map image to new voxel space (RAS orientation)

    :param nibabel.MGHImage img: the src 3D image with data and affine set
    :param np.ndarray out_affine: trg image affine
    :param np.ndarray out_shape: the trg shape information
    :param np.ndarray ras2ras: ras2ras an additional maping that should be applied (default=id to just reslice)
    :param int order: order of interpolation (0=nearest,1=linear(default),2=quadratic,3=cubic)
    :return: mapped Image data array
    """
    from scipy.ndimage import affine_transform
    from numpy.linalg import inv

    # compute vox2vox from src to trg
    vox2vox = inv(out_affine) @ ras2ras @ img.affine

    # here we apply the inverse vox2vox (to pull back the src info to the target image)
    new_data = affine_transform(img.get_data(), inv(vox2vox), output_shape=out_shape, order=order)
    return new_data 
開發者ID:Deep-MI,項目名稱:FastSurfer,代碼行數:23,代碼來源:conform.py

示例6: transform_coordinate_space

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def transform_coordinate_space(modality_1, modality_2):
    """
    Accepts nifty objects
    Transfers coordinate space from modality_2 to modality_1
    """
    aff_t1 = modality_1.affine
    aff_t2 = modality_2.affine
    inv_af_2 = np.linalg.inv(aff_t2)

    out_shape = modality_1.get_fdata().shape

    # desired transformation
    T = inv_af_2.dot(aff_t1)
    transformed = ndimage.affine_transform(modality_2.get_fdata(), T, output_shape=out_shape)

    return transformed 
開發者ID:black0017,項目名稱:MedicalZooPytorch,代碼行數:18,代碼來源:medical_image_process.py

示例7: transform_image

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def transform_image(image, angle=0.0, scale=1.0, aniso=1.0, translation=(0, 0), order=1):
    dx, dy = translation
    scale = 1.0/scale
    c = cos(angle)
    s = sin(angle)
    sm = np.array([[scale / aniso, 0], [0, scale * aniso]], 'f')
    m = np.array([[c, -s], [s, c]], 'f')
    m = np.dot(sm, m)
    w, h = image.shape
    c = np.array([w, h]) / 2.0
    d = c - np.dot(m, c) + np.array([dx * w, dy * h])
    return ndi.affine_transform(image, m, offset=d, order=order, mode="nearest", output=dtype("f")) 
開發者ID:Calamari-OCR,項目名稱:calamari,代碼行數:14,代碼來源:degrade.py

示例8: test_map_coordinates_dts

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_map_coordinates_dts():
    # check that ndimage accepts different data types for interpolation
    data = np.array([[4, 1, 3, 2],
                     [7, 6, 8, 5],
                     [3, 5, 3, 6]])
    shifted_data = np.array([[0, 0, 0, 0],
                             [0, 4, 1, 3],
                             [0, 7, 6, 8]])
    idx = np.indices(data.shape)
    dts = (np.uint8, np.uint16, np.uint32, np.uint64,
           np.int8, np.int16, np.int32, np.int64,
           np.intp, np.uintp, np.float32, np.float64)
    for order in range(0, 6):
        for data_dt in dts:
            these_data = data.astype(data_dt)
            for coord_dt in dts:
                # affine mapping
                mat = np.eye(2, dtype=coord_dt)
                off = np.zeros((2,), dtype=coord_dt)
                out = ndimage.affine_transform(these_data, mat, off)
                assert_array_almost_equal(these_data, out)
                # map coordinates
                coords_m1 = idx.astype(coord_dt) - 1
                coords_p10 = idx.astype(coord_dt) + 10
                out = ndimage.map_coordinates(these_data, coords_m1, order=order)
                assert_array_almost_equal(out, shifted_data)
                # check constant fill works
                out = ndimage.map_coordinates(these_data, coords_p10, order=order)
                assert_array_almost_equal(out, np.zeros((3,4)))
            # check shift and zoom
            out = ndimage.shift(these_data, 1)
            assert_array_almost_equal(out, shifted_data)
            out = ndimage.zoom(these_data, 1)
            assert_array_almost_equal(these_data, out) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:36,代碼來源:test_datatypes.py

示例9: test_uint64_max

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_uint64_max():
    # Test interpolation respects uint64 max.  Reported to fail at least on
    # win32 (due to the 32 bit visual C compiler using signed int64 when
    # converting between uint64 to double) and Debian on s390x.
    big = 2**64-1
    arr = np.array([big, big, big], dtype=np.uint64)
    # Tests geometric transform (map_coordinates, affine_transform)
    inds = np.indices(arr.shape) - 0.1
    x = ndimage.map_coordinates(arr, inds)
    assert_true(x[1] > (2**63))
    # Tests zoom / shift
    x = ndimage.shift(arr, 0.1)
    assert_true(x[1] > (2**63)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:15,代碼來源:test_datatypes.py

示例10: test_affine_transform01

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform01(self):
        data = numpy.array([1])
        for order in range(0, 6):
            out = ndimage.affine_transform(data, [[1]],
                                                     order=order)
            assert_array_almost_equal(out, [1]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_ndimage.py

示例11: test_affine_transform02

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform02(self):
        data = numpy.ones([4])
        for order in range(0, 6):
            out = ndimage.affine_transform(data, [[1]],
                                                     order=order)
            assert_array_almost_equal(out, [1, 1, 1, 1]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_ndimage.py

示例12: test_affine_transform03

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform03(self):
        data = numpy.ones([4])
        for order in range(0, 6):
            out = ndimage.affine_transform(data, [[1]], -1,
                                                     order=order)
            assert_array_almost_equal(out, [0, 1, 1, 1]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_ndimage.py

示例13: test_affine_transform05

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform05(self):
        data = numpy.array([[1, 1, 1, 1],
                               [1, 1, 1, 1],
                               [1, 1, 1, 1]])
        for order in range(0, 6):
            out = ndimage.affine_transform(data, [[1, 0],
                                                            [0, 1]],
                                                     [0, -1], order=order)
            assert_array_almost_equal(out, [[0, 1, 1, 1],
                                       [0, 1, 1, 1],
                                       [0, 1, 1, 1]]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:test_ndimage.py

示例14: test_affine_transform06

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform06(self):
        data = numpy.array([[4, 1, 3, 2],
                               [7, 6, 8, 5],
                               [3, 5, 3, 6]])
        for order in range(0, 6):
            out = ndimage.affine_transform(data, [[1, 0],
                                                            [0, 1]],
                                                     [0, -1], order=order)
            assert_array_almost_equal(out, [[0, 4, 1, 3],
                                       [0, 7, 6, 8],
                                       [0, 3, 5, 3]]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:test_ndimage.py

示例15: test_affine_transform07

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import affine_transform [as 別名]
def test_affine_transform07(self):
        data = numpy.array([[4, 1, 3, 2],
                               [7, 6, 8, 5],
                               [3, 5, 3, 6]])
        for order in range(0, 6):
            out = ndimage.affine_transform(data, [[1, 0],
                                                            [0, 1]],
                                                     [-1, 0], order=order)
            assert_array_almost_equal(out, [[0, 0, 0, 0],
                                       [4, 1, 3, 2],
                                       [7, 6, 8, 5]]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:test_ndimage.py


注:本文中的scipy.ndimage.affine_transform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。