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


Python Image.EXTENT属性代码示例

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


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

示例1: transformImg

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def transformImg(self, img, t):
        imgT = img.transform((int(img.size[0]*t[3]),int(img.size[1]*t[3])), Image.EXTENT, (0,0,img.size[0],img.size[1]), Image.BILINEAR)
        imgT = imgT.rotate(numpy.rad2deg(t[0]), Image.BILINEAR, expand=1)
        if t[4] == 1.:
            imgT = imgT.transpose(Image.FLIP_LEFT_RIGHT)

        # crop only valid part
        if self.crop:
            imgT = imgT.crop(self.getInscribedRectangle(t[0], (img.size[0]*t[3], img.size[1]*t[3])))

        # crop from translation
        imgT = imgT.resize((int(self.imgSize[0]*1.1), int(self.imgSize[1]*1.1)), Image.BILINEAR)
        xstart = int((imgT.size[0] // 2 - t[1]) - self.imgSize[0] // 2)
        ystart = int((imgT.size[1] // 2 - t[2]) - self.imgSize[1] // 2)
        assert xstart >= 0 and ystart >= 0
        return imgT.crop((xstart, ystart, xstart+self.imgSize[0], ystart+self.imgSize[1])) 
开发者ID:moberweger,项目名称:deep-prior,代码行数:18,代码来源:transformations.py

示例2: to_column_format

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def to_column_format(self, high_density_vertical=True):
        """
        Extract slices of an image as equal-sized blobs of column-format data.

        :param high_density_vertical: Printed line height in dots
        """
        im = self._im.transpose(Image.ROTATE_270).transpose(Image.FLIP_LEFT_RIGHT)
        line_height = 24 if high_density_vertical else 8
        width_pixels, height_pixels = im.size
        top = 0
        left = 0
        while left < width_pixels:
            box = (left, top, left + line_height, top + height_pixels)
            im_slice = im.transform((line_height, height_pixels), Image.EXTENT, box)
            im_bytes = im_slice.tobytes()
            yield(im_bytes)
            left += line_height 
开发者ID:python-escpos,项目名称:python-escpos,代码行数:19,代码来源:image.py

示例3: test_extent

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def test_extent(self):
        im = hopper('RGB')
        (w, h) = im.size
        transformed = im.transform(im.size, Image.EXTENT,
                                   (0, 0,
                                    w//2, h//2),  # ul -> lr
                                   Image.BILINEAR)

        scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0, 0, w, h))

        # undone -- precision?
        self.assert_image_similar(transformed, scaled, 23) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:14,代码来源:test_image_transform.py

示例4: test_fill

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def test_fill(self):
        for mode, pixel in [
            ['RGB', (255, 0, 0)],
            ['RGBA', (255, 0, 0, 255)],
            ['LA', (76, 0)]
        ]:
            im = hopper(mode)
            (w, h) = im.size
            transformed = im.transform(im.size, Image.EXTENT,
                                       (0, 0,
                                        w*2, h*2),
                                       Image.BILINEAR,
                                       fillcolor='red')

            self.assertEqual(transformed.getpixel((w-1, h-1)), pixel) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:17,代码来源:test_image_transform.py

示例5: test_alpha_premult_transform

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def test_alpha_premult_transform(self):

        def op(im, sz):
            (w, h) = im.size
            return im.transform(sz, Image.EXTENT,
                                (0, 0,
                                 w, h),
                                Image.BILINEAR)

        self._test_alpha_premult(op) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:12,代码来源:test_image_transform.py

示例6: apply_image

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def apply_image(self, img, interp=None):
        h, w = self.output_size
        ret = Image.fromarray(img).transform(
            size=(w, h),
            method=Image.EXTENT,
            data=self.src_rect,
            resample=interp if interp else self.interp,
            fill=self.fill,
        )
        return np.asarray(ret) 
开发者ID:facebookresearch,项目名称:detectron2,代码行数:12,代码来源:transform.py

示例7: __transformer

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def __transformer(self, box, image, method, data,
                      resample=NEAREST, fill=1):
        w = box[2] - box[0]
        h = box[3] - box[1]

        if method == AFFINE:
            data = data[0:6]

        elif method == EXTENT:
            # convert extent to an affine transform
            x0, y0, x1, y1 = data
            xs = float(x1 - x0) / w
            ys = float(y1 - y0) / h
            method = AFFINE
            data = (xs, 0, x0, 0, ys, y0)

        elif method == PERSPECTIVE:
            data = data[0:8]

        elif method == QUAD:
            # quadrilateral warp.  data specifies the four corners
            # given as NW, SW, SE, and NE.
            nw = data[0:2]
            sw = data[2:4]
            se = data[4:6]
            ne = data[6:8]
            x0, y0 = nw
            As = 1.0 / w
            At = 1.0 / h
            data = (x0, (ne[0]-x0)*As, (sw[0]-x0)*At,
                    (se[0]-sw[0]-ne[0]+x0)*As*At,
                    y0, (ne[1]-y0)*As, (sw[1]-y0)*At,
                    (se[1]-sw[1]-ne[1]+y0)*As*At)

        else:
            raise ValueError("unknown transformation method")

        if resample not in (NEAREST, BILINEAR, BICUBIC):
            raise ValueError("unknown resampling filter")

        image.load()

        self.load()

        if image.mode in ("1", "P"):
            resample = NEAREST

        self.im.transform2(box, image.im, method, data, resample, fill) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:50,代码来源:Image.py

示例8: test_basic

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import EXTENT [as 别名]
def test_basic(self):
        # PIL 1.1 has limited support for 16-bit image data.  Check that
        # create/copy/transform and save works as expected.

        def basic(mode):

            imIn = self.original.convert(mode)
            self.verify(imIn)

            w, h = imIn.size

            imOut = imIn.copy()
            self.verify(imOut)  # copy

            imOut = imIn.transform((w, h), Image.EXTENT, (0, 0, w, h))
            self.verify(imOut)  # transform

            filename = self.tempfile("temp.im")
            imIn.save(filename)

            imOut = Image.open(filename)

            self.verify(imIn)
            self.verify(imOut)

            imOut = imIn.crop((0, 0, w, h))
            self.verify(imOut)

            imOut = Image.new(mode, (w, h), None)
            imOut.paste(imIn.crop((0, 0, w//2, h)), (0, 0))
            imOut.paste(imIn.crop((w//2, 0, w, h)), (w//2, 0))

            self.verify(imIn)
            self.verify(imOut)

            imIn = Image.new(mode, (1, 1), 1)
            self.assertEqual(imIn.getpixel((0, 0)), 1)

            imIn.putpixel((0, 0), 2)
            self.assertEqual(imIn.getpixel((0, 0)), 2)

            if mode == "L":
                maximum = 255
            else:
                maximum = 32767

            imIn = Image.new(mode, (1, 1), 256)
            self.assertEqual(imIn.getpixel((0, 0)), min(256, maximum))

            imIn.putpixel((0, 0), 512)
            self.assertEqual(imIn.getpixel((0, 0)), min(512, maximum))

        basic("L")

        basic("I;16")
        basic("I;16B")
        basic("I;16L")

        basic("I") 
开发者ID:holzschu,项目名称:python3_ios,代码行数:61,代码来源:test_mode_i16.py


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