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


Python numpy.rot90方法代碼示例

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


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

示例1: show

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def show():
    """Output the contents of the buffer to Unicorn HAT HD."""
    setup()
    if _addressing_enabled:
        for address in range(8):
            display = _displays[address]
            if display.enabled:
                if _buffer_width == _buffer_height or _rotation in [0, 2]:
                    window = display.get_buffer_window(numpy.rot90(_buf, _rotation))
                else:
                    window = display.get_buffer_window(numpy.rot90(_buf, _rotation))

                _spi.xfer2([_SOF + 1 + address] + (window.reshape(768) * _brightness).astype(numpy.uint8).tolist())
                time.sleep(_DELAY)
    else:
        _spi.xfer2([_SOF] + (numpy.rot90(_buf, _rotation).reshape(768) * _brightness).astype(numpy.uint8).tolist())

    time.sleep(_DELAY) 
開發者ID:pimoroni,項目名稱:unicorn-hat-hd,代碼行數:20,代碼來源:__init__.py

示例2: augment_img

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_img(img, mode=0):
    '''Kai Zhang (github: https://github.com/cszn)
    '''
    if mode == 0:
        return img
    elif mode == 1:
        return np.flipud(np.rot90(img))
    elif mode == 2:
        return np.flipud(img)
    elif mode == 3:
        return np.rot90(img, k=3)
    elif mode == 4:
        return np.flipud(np.rot90(img, k=2))
    elif mode == 5:
        return np.rot90(img)
    elif mode == 6:
        return np.rot90(img, k=2)
    elif mode == 7:
        return np.flipud(np.rot90(img, k=3)) 
開發者ID:cszn,項目名稱:KAIR,代碼行數:21,代碼來源:utils_image.py

示例3: augment_img_tensor4

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_img_tensor4(img, mode=0):
    '''Kai Zhang (github: https://github.com/cszn)
    '''
    if mode == 0:
        return img
    elif mode == 1:
        return img.rot90(1, [2, 3]).flip([2])
    elif mode == 2:
        return img.flip([2])
    elif mode == 3:
        return img.rot90(3, [2, 3])
    elif mode == 4:
        return img.rot90(2, [2, 3]).flip([2])
    elif mode == 5:
        return img.rot90(1, [2, 3])
    elif mode == 6:
        return img.rot90(2, [2, 3])
    elif mode == 7:
        return img.rot90(3, [2, 3]).flip([2]) 
開發者ID:cszn,項目名稱:KAIR,代碼行數:21,代碼來源:utils_image.py

示例4: augment_imgs

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_imgs(img_list, hflip=True, rot=True):
    # horizontal flip OR rotate
    hflip = hflip and random.random() < 0.5
    vflip = rot and random.random() < 0.5
    rot90 = rot and random.random() < 0.5

    def _augment(img):
        if hflip:
            img = img[:, ::-1, :]
        if vflip:
            img = img[::-1, :, :]
        if rot90:
            img = img.transpose(1, 0, 2)
        return img

    return [_augment(img) for img in img_list] 
開發者ID:cszn,項目名稱:KAIR,代碼行數:18,代碼來源:utils_image.py

示例5: rotate_patches

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rotate_patches(patches_vol, patches_seg):
    # Initialize lists for rotated patches
    rotated_vol = []
    rotated_seg = []
    # Iterate over 90,180,270 degree (1*90, 2*90, 3*90)
    for times in range(1,4):
        # Iterate over each patch
        for i in range(len(patches_vol)):
            # Rotate volume & segmentation and cache rotated patches
            patch_vol_rotated = np.rot90(patches_vol[i], k=times, axes=(2,3))
            rotated_vol.append(patch_vol_rotated)
            patch_seg_rotated = np.rot90(patches_seg[i], k=times, axes=(2,3))
            rotated_seg.append(patch_seg_rotated)
    # Add rotated patches to the original patches lists
    patches_vol.extend(rotated_vol)
    patches_seg.extend(rotated_seg)
    # Return processed patches lists
    return patches_vol, patches_seg

# Flip patches at the provided axes 
開發者ID:muellerdo,項目名稱:kits19.MIScnn,代碼行數:22,代碼來源:preprocessing.py

示例6: data_aug

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def data_aug(img, mode=0):
    # data augmentation
    if mode == 0:
        return img
    elif mode == 1:
        return np.flipud(img)
    elif mode == 2:
        return np.rot90(img)
    elif mode == 3:
        return np.flipud(np.rot90(img))
    elif mode == 4:
        return np.rot90(img, k=2)
    elif mode == 5:
        return np.flipud(np.rot90(img, k=2))
    elif mode == 6:
        return np.rot90(img, k=3)
    elif mode == 7:
        return np.flipud(np.rot90(img, k=3)) 
開發者ID:guochengqian,項目名稱:TENet,代碼行數:20,代碼來源:Prepro.py

示例7: rot90

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rot90(m, k=1, axes=(0, 1)):  # pylint: disable=missing-docstring
  m_rank = tf.rank(m)
  ax1, ax2 = utils._canonicalize_axes(axes, m_rank)  # pylint: disable=protected-access

  k = k % 4
  if k == 0:
    return m
  elif k == 2:
    return flip(flip(m, ax1), ax2)
  else:
    perm = tf.range(m_rank)
    perm = tf.tensor_scatter_nd_update(perm, [[ax1], [ax2]], [ax2, ax1])

    if k == 1:
      return transpose(flip(m, ax2), perm)
    else:
      return flip(transpose(m, perm), ax2) 
開發者ID:google,項目名稱:trax,代碼行數:19,代碼來源:array_ops.py

示例8: _create_bowl

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def _create_bowl(self, altitude_changes):
        half_width = len(altitude_changes)
        height = sum(altitude_changes) + 1

        half_bowl = np.zeros((height, half_width))

        row = 0
        for idx, ac in enumerate(altitude_changes):
            half_bowl[row, idx] = 1
            for i in xrange(ac):
                row += 1
                half_bowl[row, idx] = 1

        assert row == height-1

        bowl = np.concatenate([half_bowl, np.fliplr(half_bowl)], axis=1)

        for _ in range(self.rotations):
            bowl = np.rot90(bowl)

        return bowl 
開發者ID:vicariousinc,項目名稱:pixelworld,代碼行數:23,代碼來源:pattern_generator.py

示例9: rot180

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rot180(images):
    """
    旋轉圖片180度。
    支持HW/CHW/NCHW三種格式的images。
    """
    out = np.empty(shape=images.shape, dtype=images.dtype)
    if images.ndim == 2:
        out = np.rot90(images, k=2)
    elif images.ndim == 3:
        for c in xrange(images.shape[0]):
            out[c] = np.rot90(images[c], k=2)
    elif images.ndim == 4:
        for n in xrange(images.shape[0]):
            for c in xrange(images.shape[1]):
                out[n][c] = np.rot90(images[n][c], k=2)
    else:
        raise Exception('Invalid ndim: ' + str(images.ndim) +
                        ', only support ndim between 2 and 4.')
    return out


# 給定函數f,自變量x以及對f的梯度df,求對x的梯度 
開發者ID:monitor1379,項目名稱:hamaa,代碼行數:24,代碼來源:np_utils.py

示例10: _apply_transformations

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def _apply_transformations(plot_config, data_slice):
    """Rotate, flip and zoom the data slice.

    Depending on the plot configuration, this will apply some transformations to the given data slice.

    Args:
        plot_config (mdt.visualization.maps.base.MapPlotConfig): the plot configuration
        data_slice (ndarray): the 2d slice of data to transform

    Returns:
        ndarray: the transformed 2d slice of data
    """
    if plot_config.rotate:
        data_slice = np.rot90(data_slice, plot_config.rotate // 90)

    if not plot_config.flipud:
        # by default we flipud to correct for matplotlib lower origin. If the user
        # sets flipud, we do not need to to it
        data_slice = np.flipud(data_slice)

    data_slice = plot_config.zoom.apply(data_slice)
    return data_slice 
開發者ID:robbert-harms,項目名稱:MDT,代碼行數:24,代碼來源:matplotlib_renderer.py

示例11: get_buffer_window

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def get_buffer_window(self, source):
        """Grab the correct portion of the supplied buffer for this display.

        :param source: source buffer, should be a numpy array

        """
        view = source[self.x:self.x + PANEL_SHAPE[0], self.y:self.y + PANEL_SHAPE[1]]
        return numpy.rot90(view, self.rotation + 1) 
開發者ID:pimoroni,項目名稱:unicorn-hat-hd,代碼行數:10,代碼來源:__init__.py

示例12: cce2full

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def cce2full(A):

    # Assume all square for now

    N = A.shape
    N_half = N[0]//2 + 1
    out = np.empty((A.shape[0], A.shape[0]), dtype=A.dtype)
    out[:, :N_half] = A

    out[1:, N_half:] = np.rot90(A[1:, 1:-1], 2).conj()

    # Complete the first row
    out[0, N_half:] = A[0, -2:0:-1].conj()

    return out 
開發者ID:LCAV,項目名稱:FRIDA,代碼行數:17,代碼來源:mkl_fft.py

示例13: augment_data

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def augment_data(self, game_state, training_data, row, column):
        """Loop for each self-play game.

        Runs MCTS for each game state and plays a move based on the MCTS output.
        Stops when the game is over and prints out a winner.

        Args:
            game_state: An object containing the state, pis and value.
            training_data: A list to store self play states, pis and vs.
            row: An integer indicating the length of the board row.
            column: An integer indicating the length of the board column.
        """
        state = deepcopy(game_state[0])
        psa_vector = deepcopy(game_state[1])

        if CFG.game == 2 or CFG.game == 1:
            training_data.append([state, psa_vector, game_state[2]])
        else:
            psa_vector = np.reshape(psa_vector, (row, column))

            # Augment data by rotating and flipping the game state.
            for i in range(4):
                training_data.append([np.rot90(state, i),
                                      np.rot90(psa_vector, i).flatten(),
                                      game_state[2]])

                training_data.append([np.fliplr(np.rot90(state, i)),
                                      np.fliplr(
                                          np.rot90(psa_vector, i)).flatten(),
                                      game_state[2]]) 
開發者ID:blanyal,項目名稱:alpha-zero,代碼行數:32,代碼來源:train.py

示例14: rotate

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rotate(images):
    images = np.append(images, [np.fliplr(image) for image in images], axis=0)  # 180 degree
    images = np.append(images, [np.rot90(image) for image in images], axis=0)   # 90 degree
    return images 
開發者ID:kozistr,項目名稱:rcan-tensorflow,代碼行數:6,代碼來源:util.py

示例15: rotate

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rot90 [as 別名]
def rotate(image, angle, axes=(0, 1)):
    if angle % 90 != 0:
        raise Exception('Angle must be a multiple of 90.')
    k = angle // 90
    return np.rot90(image, k, axes=axes) 
開發者ID:neptune-ai,項目名稱:open-solution-salt-identification,代碼行數:7,代碼來源:augmentation.py


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