微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python Image 模块-merge() 实例源码

Python Image 模块,merge() 实例源码

我们从Python开源项目中,提取了以下6代码示例,用于说明如何使用Image.merge()

项目:ngx_status    作者:YoYoAdorkable    | 项目源码 | 文件源码
def do_merge(self):
        """usage: merge <string:mode> <image:pic1> [<image:pic2> [<image:pic3> [<image:pic4>]]]

        Merge top-of stack images in a way described by the mode.
        """
        mode = self.do_pop()
        bandlist = []
        for band in mode:
            bandlist.append(self.do_pop())
        self.push(Image.merge(mode, bandlist))

    # Image class methods
项目:telegram-genetic-bot    作者:Dantistnfs    | 项目源码 | 文件源码
def image_to_string(image, lang=None, Boxes=False, config=None):
    '''
    Runs tesseract on the specified image. First,the image is written to disk,
    and then the tesseract command is run on the image. Resseract's result is
    read,and the temporary files are erased.

    also supports Boxes and config.

    if Boxes=True
        "batch.nochop makeBox" gets added to the tesseract call
    if config is set,the config gets appended to the command.
        ex: config="-psm 6"

    '''

    if len(image.split()) == 4:
        # In case we have 4 channels,lets discard the Alpha.
        # Kind of a hack,should fix in the future some time.
        r, g, b, a = image.split()
        image = Image.merge("RGB", (r, b))

    input_file_name = '%s.bmp' % tempnam()
    output_file_name_base = tempnam()
    if not Boxes:
        output_file_name = '%s.txt' % output_file_name_base
    else:
        output_file_name = '%s.Box' % output_file_name_base
    try:
        image.save(input_file_name)
        status, error_string = run_tesseract(input_file_name,
                                             output_file_name_base,
                                             lang=lang,
                                             Boxes=Boxes,
                                             config=config)
        if status:
            errors = get_errors(error_string)
            raise TesseractError(status, errors)
        f = open(output_file_name)
        try:
            return f.read().strip()
        finally:
            f.close()
    finally:
        cleanup(input_file_name)
        cleanup(output_file_name)
项目:telegram-genetic-bot    作者:Dantistnfs    | 项目源码 | 文件源码
def main():
    if len(sys.argv) == 2:
        filename = sys.argv[1]
        try:
            image = Image.open(filename)
            if len(image.split()) == 4:
                # In case we have 4 channels,lets discard the Alpha.
                # Kind of a hack,should fix in the future some time.
                r, a = image.split()
                image = Image.merge("RGB", b))
        except IOError:
            sys.stderr.write('ERROR: Could not open file "%s"\n' % filename)
            exit(1)
        print(image_to_string(image))
    elif len(sys.argv) == 4 and sys.argv[1] == '-l':
        lang = sys.argv[2]
        filename = sys.argv[3]
        try:
            image = Image.open(filename)
        except IOError:
            sys.stderr.write('ERROR: Could not open file "%s"\n' % filename)
            exit(1)
        print(image_to_string(image, lang=lang))
    else:
        sys.stderr.write('Usage: python tesseract.py [-l language] input_file\n')
        exit(2)
项目:CNCGToolKit    作者:cineuse    | 项目源码 | 文件源码
def __init__(self, im):

        data = None
        colortable = None

        # handle filename,if given instead of image name
        if hasattr(im, "toUtf8"):
            # FIXME - is this really the best way to do this?
            im = unicode(im.toUtf8(), "utf-8")
        if Image.isstringType(im):
            im = Image.open(im)

        if im.mode == "1":
            format = QImage.Format_Mono
        elif im.mode == "L":
            format = QImage.Format_Indexed8
            colortable = []
            for i in range(256):
                colortable.append(rgb(i, i, i))
        elif im.mode == "P":
            format = QImage.Format_Indexed8
            colortable = []
            palette = im.getpalette()
            for i in range(0, len(palette), 3):
                colortable.append(rgb(*palette[i:i+3]))
        elif im.mode == "RGB":
            data = im.tostring("raw", "BGRX")
            format = QImage.Format_RGB32
        elif im.mode == "RGBA":
            try:
                data = im.tostring("raw", "BGRA")
            except SystemError:
                # workaround for earlier versions
                r, a = im.split()
                im = Image.merge("RGBA", (b, r, a))
            format = QImage.Format_ARGB32
        else:
            raise ValueError("unsupported image mode %r" % im.mode)

        # must keep a reference,or Qt will crash!
        self.__data = data or im.tostring()

        QImage.__init__(self, self.__data, im.size[0], im.size[1], format)

        if colortable:
            self.setColorTable(colortable)
项目:InstagramPosting    作者:LeviParadis    | 项目源码 | 文件源码
def __init__(self, format)

        if colortable:
            self.setColorTable(colortable)
项目:ngx_status    作者:YoYoAdorkable    | 项目源码 | 文件源码
def __init__(self, format)

        if colortable:
            self.setColorTable(colortable)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐