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


Python Image.AFFINE属性代码示例

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


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

示例1: ScaleRotateTranslate

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def ScaleRotateTranslate(self, image, angle, center=None, new_center=None,
                             scale=None, expand=False):
        '''
        experimental - not used yet
        '''
        if center is None:
            return image.rotate(angle, expand)
        angle = -angle / 180.0 * math.pi
        nx, ny = x, y = center
        if new_center != center:
            (nx, ny) = new_center
        sx = sy = 1.0
        if scale:
            (sx, sy) = scale
        cosine = math.cos(angle)
        sine = math.sin(angle)
        a = cosine / sx
        b = sine / sx
        c = x - nx * a - ny * b
        d = -sine / sy
        e = cosine / sy
        f = y - nx * d - ny * e
        return image.transform(image.size, Image.AFFINE,
                               (a,b,c,d,e,f), resample=Image.BICUBIC) 
开发者ID:NickWaterton,项目名称:Roomba980-Python,代码行数:26,代码来源:roomba.py

示例2: _shear_x_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _shear_x_impl(pil_img, level, img_shape):
  """Applies PIL ShearX to `pil_img`.

  The ShearX operation shears the image along the horizontal axis with `level`
  magnitude.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had ShearX applied to it.
  """
  level = float_parameter(level, 0.3)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform(
      _width_height_from_img_shape(img_shape),
      Image.AFFINE,
      (1, level, 0, 0, 1, 0)) 
开发者ID:google-research,项目名称:uda,代码行数:23,代码来源:augmentation_transforms.py

示例3: _shear_y_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _shear_y_impl(pil_img, level, img_shape):
  """Applies PIL ShearY to `pil_img`.

  The ShearY operation shears the image along the vertical axis with `level`
  magnitude.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had ShearX applied to it.
  """
  level = float_parameter(level, 0.3)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform(
      _width_height_from_img_shape(img_shape),
      Image.AFFINE,
      (1, 0, 0, level, 1, 0)) 
开发者ID:google-research,项目名称:uda,代码行数:23,代码来源:augmentation_transforms.py

示例4: _translate_x_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _translate_x_impl(pil_img, level, img_shape):
  """Applies PIL TranslateX to `pil_img`.

  Translate the image in the horizontal direction by `level`
  number of pixels.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had TranslateX applied to it.
  """
  level = int_parameter(level, 10)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform(
      _width_height_from_img_shape(img_shape),
      Image.AFFINE,
      (1, 0, level, 0, 1, 0)) 
开发者ID:google-research,项目名称:uda,代码行数:23,代码来源:augmentation_transforms.py

示例5: _translate_y_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _translate_y_impl(pil_img, level, img_shape):
  """Applies PIL TranslateY to `pil_img`.

  Translate the image in the vertical direction by `level`
  number of pixels.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had TranslateY applied to it.
  """
  level = int_parameter(level, 10)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform(
      _width_height_from_img_shape(img_shape),
      Image.AFFINE,
      (1, 0, 0, 0, 1, level)) 
开发者ID:google-research,项目名称:uda,代码行数:23,代码来源:augmentation_transforms.py

示例6: scale_rotate__translate

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def scale_rotate__translate(image, angle, center=None, new_center=None, scale=None, resample=Image.BICUBIC):
    if (scale is None) and (center is None):
        return image.rotate(angle=angle, resample=resample)
    nx, ny = x, y = center
    sx = sy = 1.0
    if new_center:
        (nx, ny) = new_center
    if scale:
        (sx, sy) = (scale, scale)
    cosine = math.cos(angle)
    sine = math.sin(angle)
    a = cosine / sx
    b = sine / sx
    c = x - nx * a - ny * b
    d = -sine / sy
    e = cosine / sy
    f = y - nx * d - ny * e
    return image.transform(image.size, Image.AFFINE, (a, b, c, d, e, f), resample=resample) 
开发者ID:nigroup,项目名称:nideep,代码行数:20,代码来源:preprocessing.py

示例7: prepare_char

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def prepare_char(some_char, angle=20, shear=10, scale=2):
    phi = np.radians(np.random.uniform(-angle,angle))
    theta = np.radians(np.random.uniform(-shear,shear))
    a = scale**np.random.uniform(-1,1)
    b = scale**np.random.uniform(-1,1)
    (x,y) = some_char.size
    x = a*x
    y = b*y
    xextremes = [rot_x(phi,theta,0,0),rot_x(phi,theta,0,y),rot_x(phi,theta,x,0),rot_x(phi,theta,x,y)]
    yextremes = [rot_y(phi,theta,0,0),rot_y(phi,theta,0,y),rot_y(phi,theta,x,0),rot_y(phi,theta,x,y)]
    mnx = min(xextremes)
    mxx = max(xextremes)
    mny = min(yextremes)
    mxy = max(yextremes)

    aff_bas = np.array([[a*np.cos(phi+theta), b*np.sin(phi-theta), -mnx],[-a*np.sin(phi+theta), b*np.cos(phi-theta), -mny],[0, 0, 1]])
    aff_prm = np.linalg.inv(aff_bas)
    some_char = some_char.transform((int(mxx-mnx),int(mxy-mny)), 
                                  method = Image.AFFINE, 
                                  data = np.ndarray.flatten(aff_prm[0:2,:]))
    some_char = some_char.resize((int(32*(mxx-mnx)/105),int(32*(mxy-mny)/105)))
    
    return some_char

# Crop scaled images to character size 
开发者ID:michaelisc,项目名称:cluttered-omniglot,代码行数:27,代码来源:dataset_utils.py

示例8: _shear_x_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _shear_x_impl(pil_img, level):
  """Applies PIL ShearX to `pil_img`.

  The ShearX operation shears the image along the horizontal axis with `level`
  magnitude.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had ShearX applied to it.
  """
  level = float_parameter(level, 0.3)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform((32, 32), Image.AFFINE, (1, level, 0, 0, 1, 0)) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:20,代码来源:augmentation_transforms.py

示例9: _shear_y_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _shear_y_impl(pil_img, level):
  """Applies PIL ShearY to `pil_img`.

  The ShearY operation shears the image along the vertical axis with `level`
  magnitude.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had ShearX applied to it.
  """
  level = float_parameter(level, 0.3)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform((32, 32), Image.AFFINE, (1, 0, 0, level, 1, 0)) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:20,代码来源:augmentation_transforms.py

示例10: _translate_x_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _translate_x_impl(pil_img, level):
  """Applies PIL TranslateX to `pil_img`.

  Translate the image in the horizontal direction by `level`
  number of pixels.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had TranslateX applied to it.
  """
  level = int_parameter(level, 10)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform((32, 32), Image.AFFINE, (1, 0, level, 0, 1, 0)) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:20,代码来源:augmentation_transforms.py

示例11: _translate_y_impl

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def _translate_y_impl(pil_img, level):
  """Applies PIL TranslateY to `pil_img`.

  Translate the image in the vertical direction by `level`
  number of pixels.

  Args:
    pil_img: Image in PIL object.
    level: Strength of the operation specified as an Integer from
      [0, `PARAMETER_MAX`].

  Returns:
    A PIL Image that has had TranslateY applied to it.
  """
  level = int_parameter(level, 10)
  if random.random() > 0.5:
    level = -level
  return pil_img.transform((32, 32), Image.AFFINE, (1, 0, 0, 0, 1, level)) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:20,代码来源:augmentation_transforms.py

示例12: ScaleRotateTranslate

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def ScaleRotateTranslate(image, angle, center=None, new_center=None, scale=None, resample=Image.BICUBIC):
        if (scale is None) and (center is None):
            return image.rotate(angle=angle, resample=resample)
        nx, ny = x, y = center
        sx = sy = 1.0
        if new_center:
            (nx, ny) = new_center
        if scale:
            (sx, sy) = (scale, scale)
        cosine = math.cos(angle)
        sine = math.sin(angle)
        a = cosine / sx
        b = sine / sx
        c = x - nx * a - ny * b
        d = -sine / sy
        e = cosine / sy
        f = y - nx * d - ny * e
        return image.transform(image.size, Image.AFFINE, (a, b, c, d, e, f), resample=resample)
        # 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。 
开发者ID:KaiJin1995,项目名称:MTCNN-VGG-face,代码行数:21,代码来源:TestMyself_NEWSVM.py

示例13: affine

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def affine(img, angle, translate, scale, shear, resample=0, fillcolor=None):
    """Apply affine transformation on the image keeping image center invariant

    Args:
        img (PIL Image): PIL Image to be rotated.
        angle (float or int): rotation angle in degrees between -180 and 180, clockwise direction.
        translate (list or tuple of integers): horizontal and vertical translations (post-rotation translation)
        scale (float): overall scale
        shear (float): shear angle value in degrees between -180 to 180, clockwise direction.
        resample (``PIL.Image.NEAREST`` or ``PIL.Image.BILINEAR`` or ``PIL.Image.BICUBIC``, optional):
            An optional resampling filter.
            See `filters`_ for more information.
            If omitted, or if the image has mode "1" or "P", it is set to ``PIL.Image.NEAREST``.
        fillcolor (int): Optional fill color for the area outside the transform in the output image. (Pillow>=5.0.0)
    """
    if not _is_pil_image(img):
        raise TypeError('img should be PIL Image. Got {}'.format(type(img)))

    assert isinstance(translate, (tuple, list)) and len(translate) == 2, \
        "Argument translate should be a list or tuple of length 2"

    assert scale > 0.0, "Argument scale should be positive"

    output_size = img.size
    center = (img.size[0] * 0.5 + 0.5, img.size[1] * 0.5 + 0.5)
    matrix = _get_inverse_affine_matrix(center, angle, translate, scale, shear)
    kwargs = {"fillcolor": fillcolor} if PILLOW_VERSION[0] == '5' else {}
    return img.transform(output_size, Image.AFFINE, matrix, resample, **kwargs) 
开发者ID:ZilinGao,项目名称:Global-Second-order-Pooling-Convolutional-Networks,代码行数:30,代码来源:functional.py

示例14: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def __call__(self, img):
        """
        Args:
            img (PIL.Image): Image to be translated.
        Returns:
            PIL.Image: Randomly translated image.
        """
        if np.random.random() < 0.5:
            hshift = np.random.randint(-self.max_hshift,self.max_hshift)
            vshift = np.random.randint(-self.max_vshift,self.max_vshift)
            return img.transform(img.size, Image.AFFINE, (1, 0, hshift, 0, 1, vshift))
        return img 
开发者ID:kefth,项目名称:fashion-mnist,代码行数:14,代码来源:utils.py

示例15: shear_x

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import AFFINE [as 别名]
def shear_x(pil_img, level):
    level = float_parameter(sample_level(level), 0.3)
    if np.random.uniform() > 0.5:
        level = -level
    return pil_img.transform((IMAGE_SIZE, IMAGE_SIZE),
                            Image.AFFINE, (1, level, 0, 0, 1, 0),
                            resample=Image.BILINEAR) 
开发者ID:AakashKumarNain,项目名称:AugMix_TF2,代码行数:9,代码来源:augmentation.py


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