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


Python ndimage.shift方法代碼示例

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


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

示例1: test_boundaries

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def test_boundaries(self):
        def shift(x):
            return (x[0] + 0.5,)

        data = numpy.array([1,2,3,4.])
        expected = {'constant': [1.5,2.5,3.5,-1,-1,-1,-1],
                    'wrap': [1.5,2.5,3.5,1.5,2.5,3.5,1.5],
                    'mirror': [1.5,2.5,3.5,3.5,2.5,1.5,1.5],
                    'nearest': [1.5,2.5,3.5,4,4,4,4]}

        for mode in expected:
            assert_array_equal(expected[mode],
                               ndimage.geometric_transform(data,shift,
                                                           cval=-1,mode=mode,
                                                           output_shape=(7,),
                                                           order=1)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_ndimage.py

示例2: test_uint64_max

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [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

示例3: _shift_grid_by_linear

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def _shift_grid_by_linear(self, dx):
        axes = sorted(dx.keys())
        shift = np.zeros(len(self.axes))
        for i, d in dx.items():
            shift[i] = d
        shift_px = shift/self.spacing
        ret = copy.copy(self)
        if np.isrealobj(self.matrix):
            ret.matrix = spnd.shift(self.matrix, -shift_px, order=1, mode='nearest')
        else:
            real, imag = self.matrix.real.copy(), self.matrix.imag.copy()
            ret.matrix = np.empty_like(matrix)
            spnd.shift(real, -shift_px, output=ret.matrix.real, order=1, mode='nearest')
            spnd.shift(imag, -shift_px, output=ret.matrix.imag, order=1, mode='nearest')

        for i in axes:
            ret.axes[i] = Axis(grid_node=self.axes[i].grid_node + dx[i],
                               grid=self.axes[i].grid + dx[i])

        return ret 
開發者ID:skuschel,項目名稱:postpic,代碼行數:22,代碼來源:datahandling.py

示例4: test_misaligned_canned_images_fast

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def test_misaligned_canned_images_fast(self):
        """ shift images from skimage.data by entire pixels.
	   We don't expect perfect alignment."""
        original = TEST_IMAGE
        misaligned = [
            ndi.shift(original, (randint(-4, 4), randint(-4, 4))) for _ in range(5)
        ]

        aligned = ialign(misaligned, reference=original, fast=True)

        # TODO: find a better figure-of-merit for alignment
        for im in aligned:
            # edge will be filled with zeros, we ignore
            diff = np.abs(original[5:-5, 5:-5] - im[5:-5, 5:-5])

            # Want less than 1% difference
            percent_diff = np.sum(diff) / (
                diff.size * (original.max() - original.min())
            )
            self.assertLess(percent_diff, 1) 
開發者ID:LaurentRDC,項目名稱:scikit-ued,代碼行數:22,代碼來源:test_alignment.py

示例5: test_misaligned_canned_images_notfast

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def test_misaligned_canned_images_notfast(self):
        """ shift images from skimage.data by entire pixels.
	   We don't expect perfect alignment."""
        original = TEST_IMAGE
        misaligned = [
            ndi.shift(original, (randint(-4, 4), randint(-4, 4))) for _ in range(5)
        ]

        aligned = ialign(misaligned, reference=original, fast=False)

        # TODO: find a better figure-of-merit for alignment
        for im in aligned:
            # edge will be filled with zeros, we ignore
            diff = np.abs(original[5:-5, 5:-5] - im[5:-5, 5:-5])

            # Want less than 1% difference
            percent_diff = np.sum(diff) / (
                diff.size * (original.max() - original.min())
            )
            self.assertLess(percent_diff, 1) 
開發者ID:LaurentRDC,項目名稱:scikit-ued,代碼行數:22,代碼來源:test_alignment.py

示例6: __init__

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def __init__(self, p, max_shift, bins_per_semitone,
                 target_type='chords_maj_min'):
        """
        Augmenter that shifts by semitones a spectrum with logarithmically
        spaced frequency bins.

        :param p: percentage of data to be shifted
        :param max_shift: maximum number of semitones to shift
        :param bins_per_semitone: number of spectrogram bins per semitone
        :param target_type: specifies target type
        """
        self.p = p
        self.max_shift = max_shift
        self.bins_per_semitone = bins_per_semitone

        if target_type == 'chords_maj_min':
            self.adapt_targets = self._adapt_targets_chords_maj_min
        elif target_type == 'chroma':
            self.adapt_targets = self._adapt_targets_chroma 
開發者ID:fdlm,項目名稱:chordrec,代碼行數:21,代碼來源:augmenters.py

示例7: __call__

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def __call__(self, batch_iterator):
        """
        :param batch_iterator: data iterator that yields the data to be
                               augmented
        :return: augmented data/target pairs
        """
        for data, targets in batch_iterator:
            batch_size = len(data)

            shifts = np.random.rand(batch_size) * 2 * self.max_shift - \
                self.max_shift

            # zero out shifts for 1-p percentage
            no_shift = random.sample(range(batch_size),
                                     int(batch_size * (1 - self.p)))
            shifts[no_shift] = 0

            new_data = np.empty_like(data)
            for i in range(batch_size):
                new_data[i] = shift(
                    data[i], (shifts[i] * self.bins_per_semitone, 0))

            yield new_data, targets 
開發者ID:fdlm,項目名稱:chordrec,代碼行數:25,代碼來源:augmenters.py

示例8: __call__

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def __call__(self, sample):
        image_gt, image_input, filename = sample['image_gt'], sample['image_input'], sample['filename']

        if 'mask' in sample:
            mask =  sample['mask']

        shift = np.random.choice([0, 10, 20, 30])
        image_gt = np.roll(image_gt,(shift,shift),(0,1))
        sample['image_gt'] = image_gt
        image_input = np.roll(image_input,(shift,shift),(0,1))
        if 'mask' in sample:
            sample['image_input'] = image_input
            mask = np.roll(mask,(shift,shift),(0,1))
            assert np.array_equal(mask[:2,:2,0], np.array([[1,0],[0,0]]))
            sample['mask'] = mask
        return sample 
開發者ID:cig-skoltech,項目名稱:deep_demosaick,代碼行數:18,代碼來源:transform.py

示例9: load_transform

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def load_transform(image_path, angle=0., s=(0,0), size=(20,20)):
    #Load the image
    original = imread(image_path, flatten=True)
    #Rotate the image
    rotated = np.maximum(np.minimum(rotate(original, angle=angle, cval=1.), 1.), 0.)
    #Shift the image
    shifted = shift(rotated, shift=s)
    #Resize the image
    resized = np.asarray(imresize(rotated, size=size), dtype=np.float32) / 255 #Note here we coded manually as np.float32, it should be tf.float32
    #Invert the image
    inverted = 1. - resized
    max_value = np.max(inverted)
    if max_value > 0:
        inverted /= max_value
    return inverted 
開發者ID:hmishra2250,項目名稱:NTM-One-Shot-TF,代碼行數:17,代碼來源:Images.py

示例10: load_transform

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def load_transform(image_path, angle=0., s=(0, 0), size=(20, 20)):
    # Load the image
    original = imread(image_path, flatten=True)
    # Rotate the image
    rotated = np.maximum(np.minimum(rotate(original, angle=angle, cval=1.), 1.), 0.)
    # Shift the image
    shifted = shift(rotated, shift=s)
    # Resize the image
    resized = np.asarray(scipy.misc.imresize(rotated, size=size), dtype=theano.config.floatX) / 255.
    # Invert the image
    inverted = 1. - resized
    max_value = np.max(inverted)
    if max_value > 0.:
        inverted /= max_value
    return inverted 
開發者ID:tristandeleu,項目名稱:ntm-one-shot,代碼行數:17,代碼來源:images.py

示例11: test_map_coordinates_dts

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [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

示例12: test_uint64_max

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [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

示例13: test_boundaries2

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import shift [as 別名]
def test_boundaries2(self):
        def shift(x):
            return (x[0] - 0.9,)

        data = numpy.array([1,2,3,4])
        expected = {'constant': [-1,1,2,3],
                    'wrap': [3,1,2,3],
                    'mirror': [2,1,2,3],
                    'nearest': [1,1,2,3]}

        for mode in expected:
            assert_array_equal(expected[mode],
                               ndimage.geometric_transform(data,shift,
                                                           cval=-1,mode=mode,
                                                           output_shape=(4,))) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:17,代碼來源:test_ndimage.py

示例14: test_map_coordinates02

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

示例15: test_shift01

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


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