Python PIL.Image 模块,QUAD 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用PIL.Image.QUAD

项目:claptcha    作者:kuszaj    | 项目源码 | 文件源码
def _rndLetterTransform(self, image):
        """Randomly morph a single character."""
        w, h = image.size

        dx = w * random.uniform(0.2, 0.7)
        dy = h * random.uniform(0.2, 0.7)

        x1, y1 = self.__class__._rndPointDisposition(dx, dy)
        x2, y2 = self.__class__._rndPointDisposition(dx, dy)

        w += abs(x1) + abs(x2)
        h += abs(x1) + abs(x2)

        quad = self.__class__._quadPoints((w, h), (x1, y1), (x2, y2))

        return image.transform(image.size, Image.QUAD,
                               data=quad, resample=self.resample)
项目:vsi_common    作者:VisionSystemsInc    | 项目源码 | 文件源码
def sample_patch(image, corners, patch_size, check_bounds=True):
  """ return an Image of size patch_size, or None if the patch is outside image bounds """
  if check_bounds:
    if any([c[0] < 0 or c[0] >= image.size[0] or c[1] < 0 or c[1] >= image.size[1] for c in corners]):
      return None
  corner_verts = (corners[0][0], corners[0][1],
          corners[1][0], corners[1][1],
          corners[2][0], corners[2][1],
          corners[3][0], corners[3][1])
  # transform is counting on patch_size to be a tuple, not numpy array
  patch_size_tuple = (patch_size[0], patch_size[1])
  return image.transform(patch_size_tuple, Image.QUAD, corner_verts, Image.NEAREST)
项目:claptcha    作者:kuszaj    | 项目源码 | 文件源码
def _rndLineTransform(self, image):
        """Randomly morph Image object with drawn line."""
        w, h = image.size

        dx = w * random.uniform(0.2, 0.5)
        dy = h * random.uniform(0.2, 0.5)

        x1, y1 = [abs(z) for z in self.__class__._rndPointDisposition(dx, dy)]
        x2, y2 = [abs(z) for z in self.__class__._rndPointDisposition(dx, dy)]

        quad = self.__class__._quadPoints((w, h), (x1, y1), (x2, y2))

        return image.transform(image.size, Image.QUAD,
                               data=quad, resample=self.resample)
项目:claptcha    作者:kuszaj    | 项目源码 | 文件源码
def _quadPoints(size, disp1, disp2):
        """Return points for QUAD transformation."""
        w, h = size
        x1, y1 = disp1
        x2, y2 = disp2

        return (
            x1,    -y1,
            -x1,    h + y2,
            w + x2, h - y2,
            w - x2, y1
        )