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


Python transform.ProjectiveTransform方法代碼示例

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


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

示例1: shear

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import ProjectiveTransform [as 別名]
def shear(X, skew):
    ''' given a 2D image, shear and return a 2D image
    
    parameters:
        X is the 2D image of shape (nRows, nColumns)
        skew is the amount to shear in the range 0 to 1.0
    '''
    
    rows = X.shape[0]
    cols = X.shape[1]    
    ratioY = skew*cols/rows
    matrix =  np.array( [[1, ratioY, 0] ,[0, 1, 0] ,[0, 0, 1 ]])                                         
    tp=af.ProjectiveTransform(matrix=matrix) 
    #tp  = tf.AffineTransform(scale=(.3,.3), shear=skew)    
    f = af.warp(X, tp)      
    return f
# 
# class file_names(object):
#     ''' store variants of file a file name with .jpg, .png, .box variations
#     '''
#     def __init__(selp, base_name, dir_name = ''):
#         base = base_name
#         jpeg = base_name + '.jpg'
#         png = base_name + '.png'
#         box = base_name + '.box' 
開發者ID:rrlyman,項目名稱:PythonMachineLearningExamples,代碼行數:27,代碼來源:ocr_utils.py

示例2: shear

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import ProjectiveTransform [as 別名]
def shear(X, skew):
    rows = X.shape[0]
    cols = X.shape[1]    
    ratioY = skew*cols/rows
    matrix =  np.array( [[1, ratioY, 0] ,[0, 1, 0] ,[0, 0, 1 ]])                                         
    tp=tf.ProjectiveTransform(matrix=matrix) 
    f = tf.warp(X, tp)      
    return f

# make some skewed versions of the shapes 
開發者ID:rrlyman,項目名稱:PythonMachineLearningExamples,代碼行數:12,代碼來源:q3_removing_affine_distortion.py

示例3: run

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import ProjectiveTransform [as 別名]
def run(self):
        """
        Run nowcasting calculations.

        Returns
        -------
        nowcasts : 3D numpy array of shape (lead_steps, dim_x, dim_y).

        """

        # define available transformations dictionary
        transformations = {'euclidean': sktf.EuclideanTransform(),
                           'similarity': sktf.SimilarityTransform(),
                           'affine': sktf.AffineTransform(),
                           'projective': sktf.ProjectiveTransform()}

        # scale input data to uint8 [0-255] with self.scaler
        data_scaled, c1, c2 = self.scaler(self.input_data)

        # set up transformer object
        trf = transformations[self.warper]

        # obtain source and target points
        if self.extrapolation == "linear":
            pts_source, pts_target_container = _sparse_linear(data_instance=data_scaled,
                                                              of_params=self.of_params,
                                                              lead_steps=self.lead_steps)
        elif self.extrapolation == "simple_delta":
            pts_source, pts_target_container = _sparse_sd(data_instance=data_scaled,
                                                          of_params=self.of_params,
                                                          lead_steps=self.lead_steps)

        # now we can start to find nowcasted image
        # for every candidate of projected sets of points

        # container for our nowcasts
        last_frame = data_scaled[-1]
        nowcst_frames = []

        for lead_step, pts_target in enumerate(pts_target_container):

            # estimate transformation matrix
            # based on source and traget points
            trf.estimate(pts_source, pts_target)

            # make a nowcast
            nowcst_frame = sktf.warp(last_frame/255, trf.inverse)
            # transformations dealing with strange behaviour
            nowcst_frame = (nowcst_frame*255).astype('uint8')
            # add to the container
            nowcst_frames.append(nowcst_frame)

        nowcst_frames = np.stack(nowcst_frames, axis=0)

        nowcst_frames = self.inverse_scaler(nowcst_frames, c1, c2)

        return nowcst_frames 
開發者ID:hydrogo,項目名稱:rainymotion,代碼行數:59,代碼來源:models.py

示例4: projective_transform_by_points

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import ProjectiveTransform [as 別名]
def projective_transform_by_points(x, src, dst, map_args={}, output_shape=None, order=1, mode='constant', cval=0.0, clip=True, preserve_range=False):
    """Projective transform by given coordinates, usually 4 coordinates. see `scikit-image <http://scikit-image.org/docs/dev/auto_examples/applications/plot_geometric.html>`_.

    Parameters
    -----------
    x : numpy array
        An image with dimension of [row, col, channel] (default).
    src : list or numpy
        The original coordinates, usually 4 coordinates of (x, y).
    dst : list or numpy
        The coordinates after transformation, the number of coordinates is the same with src.
    map_args : dict, optional
        Keyword arguments passed to inverse_map.
    output_shape : tuple (rows, cols), optional
        Shape of the output image generated. By default the shape of the input image is preserved. Note that, even for multi-band images, only rows and columns need to be specified.
    order : int, optional
        The order of interpolation. The order has to be in the range 0-5:

        - 0 Nearest-neighbor
        - 1 Bi-linear (default)
        - 2 Bi-quadratic
        - 3 Bi-cubic
        - 4 Bi-quartic
        - 5 Bi-quintic
    mode : {‘constant’, ‘edge’, ‘symmetric’, ‘reflect’, ‘wrap’}, optional
        Points outside the boundaries of the input are filled according to the given mode. Modes match the behaviour of numpy.pad.
    cval : float, optional
        Used in conjunction with mode ‘constant’, the value outside the image boundaries.
    clip : bool, optional
        Whether to clip the output to the range of values of the input image. This is enabled by default, since higher order interpolation may produce values outside the given input range.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input image is converted according to the conventions of img_as_float.

    Examples
    --------
    >>> Assume X is an image from CIFAR 10, i.e. shape == (32, 32, 3)
    >>> src = [[0,0],[0,32],[32,0],[32,32]]
    >>> dst = [[10,10],[0,32],[32,0],[32,32]]
    >>> x = projective_transform_by_points(X, src, dst)

    References
    -----------
    - `scikit-image : geometric transformations <http://scikit-image.org/docs/dev/auto_examples/applications/plot_geometric.html>`_
    - `scikit-image : examples <http://scikit-image.org/docs/dev/auto_examples/index.html>`_
    """
    if type(src) is list:   # convert to numpy
        src = np.array(src)
    if type(dst) is list:
        dst = np.array(dst)
    if np.max(x)>1:         # convert to [0, 1]
        x = x/255

    m = transform.ProjectiveTransform()
    m.estimate(dst, src)
    warped = transform.warp(x, m,  map_args=map_args, output_shape=output_shape, order=order, mode=mode, cval=cval, clip=clip, preserve_range=preserve_range)
    return warped

# Numpy and PIL 
開發者ID:zjuela,項目名稱:LapSRN-tensorflow,代碼行數:60,代碼來源:prepro.py


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