当前位置: 首页>>代码示例>>Python>>正文


Python transform.warp方法代码示例

本文整理汇总了Python中skimage.transform.warp方法的典型用法代码示例。如果您正苦于以下问题:Python transform.warp方法的具体用法?Python transform.warp怎么用?Python transform.warp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skimage.transform的用法示例。


在下文中一共展示了transform.warp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: shear

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [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: _prepare_images

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def _prepare_images(path_out, im_size=IMAGE_SIZE):
    """ generate and prepare synth. images for registration

    :param str path_out: path to the folder
    :param tuple(int,int) im_size: desired image size
    :return tuple(str,str): paths to target and source image
    """
    image = resize(data.astronaut(), output_shape=im_size, mode='constant')
    img_target = random_noise(image, var=IMAGE_NOISE)
    path_img_target = os.path.join(path_out, NAME_IMAGE_TARGET)
    io.imsave(path_img_target, img_target)

    # warp synthetic image
    tform = AffineTransform(scale=(0.9, 0.9),
                            rotation=0.2,
                            translation=(200, -50))
    img_source = warp(image, tform.inverse, output_shape=im_size)
    img_source = random_noise(img_source, var=IMAGE_NOISE)
    path_img_source = os.path.join(path_out, NAME_IMAGE_SOURCE)
    io.imsave(path_img_source, img_source)
    return path_img_target, path_img_source 
开发者ID:Borda,项目名称:BIRL,代码行数:23,代码来源:bm_comp_perform.py

示例3: test_shear_x

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def test_shear_x():
    image = np.random.randint(low=0, high=255, size=(4, 4, 3), dtype=np.uint8)
    color = tf.constant([255, 0, 255], tf.uint8)
    level = tf.random.uniform(shape=(), minval=0, maxval=1)

    tf_image = tf.constant(image)
    sheared_img = transform_ops.shear_x(tf_image, level, replace=color)
    transform_matrix = transform.AffineTransform(
        np.array([[1, level.numpy(), 0], [0, 1, 0], [0, 0, 1]])
    )
    expected_img = transform.warp(
        image, transform_matrix, order=0, cval=-1, preserve_range=True
    )

    mask = np.where(expected_img == -1)
    expected_img[mask[0], mask[1], :] = color

    np.testing.assert_equal(sheared_img.numpy(), expected_img)


# TODO: Parameterize on dtypes 
开发者ID:tensorflow,项目名称:addons,代码行数:23,代码来源:transform_ops_test.py

示例4: test_shear_y

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def test_shear_y():
    image = np.random.randint(low=0, high=255, size=(4, 4, 3), dtype=np.uint8)
    color = tf.constant([255, 0, 255], tf.dtypes.uint8)
    level = tf.random.uniform(shape=(), minval=0, maxval=1)

    tf_image = tf.constant(image)
    sheared_img = transform_ops.shear_y(image=tf_image, level=level, replace=color)
    transform_matrix = transform.AffineTransform(
        np.array([[1, 0, 0], [level.numpy(), 1, 0], [0, 0, 1]])
    )
    expected_img = transform.warp(
        image, transform_matrix, order=0, cval=-1, preserve_range=True
    )

    mask = np.where(expected_img == -1)
    expected_img[mask[0], mask[1], :] = color

    np.testing.assert_equal(sheared_img.numpy(), expected_img) 
开发者ID:tensorflow,项目名称:addons,代码行数:20,代码来源:transform_ops_test.py

示例5: distort_affine_skimage

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def distort_affine_skimage(image, rotation=10.0, shear=5.0, random_state=None):
    if random_state is None:
        random_state = np.random.RandomState(None)

    rot = np.deg2rad(np.random.uniform(-rotation, rotation))
    sheer = np.deg2rad(np.random.uniform(-shear, shear))

    shape = image.shape
    shape_size = shape[:2]
    center = np.float32(shape_size) / 2. - 0.5

    pre = transform.SimilarityTransform(translation=-center)
    affine = transform.AffineTransform(rotation=rot, shear=sheer, translation=center)
    tform = pre + affine

    distorted_image = transform.warp(image, tform.params, mode='reflect')

    return distorted_image.astype(np.float32) 
开发者ID:rwightman,项目名称:tensorflow-litterbox,代码行数:20,代码来源:image_processing_common.py

示例6: __call__

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def __call__(self, img):
        img_data = np.array(img)
        h, w, n_chan = img_data.shape
        scale_x = np.random.uniform(*self.scale_range)
        scale_y = np.random.uniform(*self.scale_range)
        scale = (scale_x, scale_y)
        rotation = np.random.uniform(*self.rotation_range)
        shear = np.random.uniform(*self.shear_range)
        translation = (
            np.random.uniform(*self.translation_range) * w,
            np.random.uniform(*self.translation_range) * h
        )
        af = AffineTransform(scale=scale, shear=shear, rotation=rotation,
                             translation=translation)
        img_data1 = warp(img_data, af.inverse)
        img1 = Image.fromarray(np.uint8(img_data1 * 255))
        return img1 
开发者ID:apsdehal,项目名称:Face-Recognition,代码行数:19,代码来源:transforms.py

示例7: lfw_imgs

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def lfw_imgs(alignment):
    if alignment == 'landmarks':
        dataset = dp.dataset.LFW('original')
        imgs = dataset.imgs
        landmarks = dataset.landmarks('68')
        n_landmarks = 68
        landmarks_mean = np.mean(landmarks, axis=0)
        landmarks_mean = np.array([landmarks_mean[:n_landmarks],
                                   landmarks_mean[n_landmarks:]])
        aligned_imgs = []
        for img, points in zip(imgs, landmarks):
            points = np.array([points[:n_landmarks], points[n_landmarks:]])
            transf = transform.estimate_transform('similarity',
                                                  landmarks_mean.T, points.T)
            img = img / 255.
            img = transform.warp(img, transf, order=3)
            img = np.round(img*255).astype(np.uint8)
            aligned_imgs.append(img)
        imgs = np.array(aligned_imgs)
    else:
        dataset = dp.dataset.LFW(alignment)
        imgs = dataset.imgs
    return imgs 
开发者ID:andersbll,项目名称:autoencoding_beyond_pixels,代码行数:25,代码来源:lfw.py

示例8: transform_img__

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def transform_img__(self, img, fn, emotion):
        self.images[fn] = {'Image': img, 'Emotion': emotion}                                            # Store original
        counter = 0

        self.images["Trans" + str(counter) + "_" + fn] = {'Image': np.fliplr(img), 'Emotion': emotion}  # FLIP the image
        counter += 1

        for deg in range(-10, 15, 5):                                        # ROTATE to be robust to camera orientation
            if deg == 0:
                continue

            self.images["Trans" + str(counter) + "_" + fn] = {'Image': tf.rotate(img, deg), 'Emotion': emotion}
            counter += 1

        lenX, lenY = img.shape                                                           # CROP based on rough heuristic
        for crop_size in range(8, 14, 2):
            cropped = img[lenX / crop_size: - lenX / crop_size, lenY / crop_size: - lenY / crop_size]
            self.images["Trans" + str(counter) + "_" + fn] = {'Image': cropped, 'Emotion': emotion}
            counter += 1

        for i in range(2):                                           # SCALE down images (random factor btw 1.1 to 1.21)
            scale_factor = math.sqrt(1.1) ** np.random.randint(2, 5)
            scaled_img = tf.warp(img, tf.AffineTransform(scale=(scale_factor, scale_factor)))
            self.images["Trans" + str(counter) + "_" + fn] = {'Image': scaled_img, 'Emotion': emotion}
            counter += 1 
开发者ID:muxspace,项目名称:facial_expressions,代码行数:27,代码来源:JN721.py

示例9: function

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def function(self, x, y):

        signal2D = self.signal.data
        order = self.order
        d11 = self.d11.value
        d12 = self.d12.value
        d21 = self.d21.value
        d22 = self.d22.value
        t1 = self.t1.value
        t2 = self.t2.value

        D = np.array([[d11, d12, t1], [d21, d22, t2], [0.0, 0.0, 1.0]])

        shifty, shiftx = np.array(signal2D.shape[:2]) / 2

        shift = tf.SimilarityTransform(translation=[-shiftx, -shifty])
        tform = tf.AffineTransform(matrix=D)
        shift_inv = tf.SimilarityTransform(translation=[shiftx, shifty])

        transformed = tf.warp(
            signal2D, (shift + (tform + shift_inv)).inverse, order=order
        )

        return transformed 
开发者ID:pyxem,项目名称:pyxem,代码行数:26,代码来源:scalable_reference_pattern.py

示例10: run

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def run(self, stack: ImageStack, transforms_list: TransformsList,
            in_place: bool=False, verbose: bool=False, *args, **kwargs) -> Optional[ImageStack]:
        if not in_place:
            # create a copy of the ImageStack, call apply on that stack with in_place=True
            image_stack = deepcopy(stack)
            self.run(image_stack, transforms_list, in_place=True, **kwargs)
            return image_stack
        if verbose and StarfishConfig().verbose:
            transforms_list.transforms = tqdm(transforms_list.transforms)
        all_axes = {Axes.ROUND, Axes.CH, Axes.ZPLANE}
        for selector, _, transformation_object in transforms_list.transforms:
            other_axes = all_axes - set(selector.keys())
            # iterate through remaining axes
            for axes in stack._iter_axes(other_axes):
                # combine all axes data to select one tile
                selector.update(axes)  # type: ignore
                selected_image, _ = stack.get_slice(selector)
                warped_image = warp(selected_image, transformation_object, **kwargs
                                    ).astype(np.float32)
                stack.set_slice(selector, warped_image)
        return None 
开发者ID:spacetx,项目名称:starfish,代码行数:23,代码来源:warp.py

示例11: warp

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def warp(
        image: xr.DataArray,
        transformation_object: GeometricTransform,
        **kwargs
) -> xr.DataArray:
    """
    Wrapper around :py:func:`skimage.transform.warp`. Warps an image according to a
    given coordinate transformation.

    Parameters
    ----------
    image : xr.DataArray
        The image to be transformed
    transformation_object : :py:class:`~skimage.transform._geometric.GeometricTransform`
        The transformation object to apply.

    Returns
    -------
    np.ndarray :
        the warped image.
    """
    return transform.warp(image, transformation_object, **kwargs) 
开发者ID:spacetx,项目名称:starfish,代码行数:24,代码来源:warp.py

示例12: align_face

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def align_face(self,
                   image,
                   face_rect, *,
                   dim=96,
                   border=0,
                   mask=FaceAlignMask.INNER_EYES_AND_BOTTOM_LIP):
        mask = np.array(mask.value)

        landmarks = self.get_landmarks(image, face_rect)
        proper_landmarks = border + dim * self.face_template[mask]
        A = np.hstack([landmarks[mask], np.ones((3, 1))]).astype(np.float64)
        B = np.hstack([proper_landmarks, np.ones((3, 1))]).astype(np.float64)
        T = np.linalg.solve(A, B).T

        wrapped = tr.warp(image,
                          tr.AffineTransform(T).inverse,
                          output_shape=(dim + 2 * border, dim + 2 * border),
                          order=3,
                          mode='constant',
                          cval=0,
                          clip=True,
                          preserve_range=True)

        return wrapped 
开发者ID:meownoid,项目名称:face-identification-tpe,代码行数:26,代码来源:preprocessing.py

示例13: scale_mask

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def scale_mask(mask, factor=1.05):
  nzy, nzx, _ = mask.nonzero()
  if nzy.size == 0:
    return mask
  #center_y, center_x = nzy.mean(), nzx.mean()
  #print center_y, center_x
  center_y, center_x = (nzy.max() + nzy.min()) / 2, (nzx.max() + nzx.min()) / 2
  #print center_y, center_x

  shift_ = SimilarityTransform(translation=[-center_x, -center_y])
  shift_inv = SimilarityTransform(translation=[center_x, center_y])

  A = SimilarityTransform(scale=(factor, factor))
  mask_out = warp(mask, (shift_ + (A + shift_inv)).inverse)
  mask_out = (mask_out > 0.5).astype("float32")
  #import matplotlib.pyplot as plt
  #im = numpy.concatenate([mask, mask, mask_out],axis=2)
  #plt.imshow(im)
  #plt.show()
  return mask_out 
开发者ID:JonathonLuiten,项目名称:PReMVOS,代码行数:22,代码来源:MaskDamager.py

示例14: augment

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def augment(
        rotation_fn=lambda: np.random.random_integers(0, 360),
        translation_fn=lambda: (np.random.random_integers(-20, 20), np.random.random_integers(-20, 20)),
        scale_factor_fn=random_zoom_range(),
        shear_fn=lambda: np.random.random_integers(-10, 10)
):
    def call(x):
        rotation = rotation_fn()
        translation = translation_fn()
        scale = scale_factor_fn()
        shear = shear_fn()

        tf_augment = AffineTransform(scale=scale, rotation=np.deg2rad(rotation), translation=translation, shear=np.deg2rad(shear))
        tf = tf_center + tf_augment + tf_uncenter

        x = warp(x, tf, order=1, preserve_range=True, mode='symmetric')

        return x

    return call 
开发者ID:mctigger,项目名称:KagglePlanetPytorch,代码行数:22,代码来源:transforms.py

示例15: augment_deterministic

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import warp [as 别名]
def augment_deterministic(
        rotation=0,
        translation=0,
        scale_factor=1,
        shear=0
):
    def call(x):
        scale = scale_factor, scale_factor
        rotation_tmp = rotation

        tf_augment = AffineTransform(
            scale=scale,
            rotation=np.deg2rad(rotation_tmp),
            translation=translation,
            shear=np.deg2rad(shear)
        )
        tf = tf_center + tf_augment + tf_uncenter

        x = warp(x, tf, order=1, preserve_range=True, mode='symmetric')

        return x

    return call 
开发者ID:mctigger,项目名称:KagglePlanetPytorch,代码行数:25,代码来源:transforms.py


注:本文中的skimage.transform.warp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。