1. <legend id='7aEB6'><style id='7aEB6'><dir id='7aEB6'><q id='7aEB6'></q></dir></style></legend>
    <tfoot id='7aEB6'></tfoot>
    • <bdo id='7aEB6'></bdo><ul id='7aEB6'></ul>

      <i id='7aEB6'><tr id='7aEB6'><dt id='7aEB6'><q id='7aEB6'><span id='7aEB6'><b id='7aEB6'><form id='7aEB6'><ins id='7aEB6'></ins><ul id='7aEB6'></ul><sub id='7aEB6'></sub></form><legend id='7aEB6'></legend><bdo id='7aEB6'><pre id='7aEB6'><center id='7aEB6'></center></pre></bdo></b><th id='7aEB6'></th></span></q></dt></tr></i><div id='7aEB6'><tfoot id='7aEB6'></tfoot><dl id='7aEB6'><fieldset id='7aEB6'></fieldset></dl></div>
    1. <small id='7aEB6'></small><noframes id='7aEB6'>

    2. 用 Python 水平组合多张图像

      Combine several images horizontally with Python(用 Python 水平组合多张图像)
        <tfoot id='g8sh5'></tfoot>
          <tbody id='g8sh5'></tbody>

        • <small id='g8sh5'></small><noframes id='g8sh5'>

          • <bdo id='g8sh5'></bdo><ul id='g8sh5'></ul>
            <legend id='g8sh5'><style id='g8sh5'><dir id='g8sh5'><q id='g8sh5'></q></dir></style></legend>

              <i id='g8sh5'><tr id='g8sh5'><dt id='g8sh5'><q id='g8sh5'><span id='g8sh5'><b id='g8sh5'><form id='g8sh5'><ins id='g8sh5'></ins><ul id='g8sh5'></ul><sub id='g8sh5'></sub></form><legend id='g8sh5'></legend><bdo id='g8sh5'><pre id='g8sh5'><center id='g8sh5'></center></pre></bdo></b><th id='g8sh5'></th></span></q></dt></tr></i><div id='g8sh5'><tfoot id='g8sh5'></tfoot><dl id='g8sh5'><fieldset id='g8sh5'></fieldset></dl></div>
                本文介绍了用 Python 水平组合多张图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I am trying to horizontally combine some JPEG images in Python.

                Problem

                I have 3 images - each is 148 x 95 - see attached. I just made 3 copies of the same image - that is why they are the same.

                My attempt

                I am trying to horizontally join them using the following code:

                import sys
                from PIL import Image
                
                list_im = ['Test1.jpg','Test2.jpg','Test3.jpg']
                
                # creates a new empty image, RGB mode, and size 444 by 95
                new_im = Image.new('RGB', (444,95))
                
                for elem in list_im:
                    for i in xrange(0,444,95):
                        im=Image.open(elem)
                        new_im.paste(im, (i,0))
                new_im.save('test.jpg')
                

                However, this is producing the output attached as test.jpg.

                Question

                Is there a way to horizontally concatenate these images such that the sub-images in test.jpg do not have an extra partial image showing?

                Additional Information

                I am looking for a way to horizontally concatenate n images. I would like to use this code generally so I would prefer to:

                • not to hard-code image dimensions, if possible
                • specify dimensions in one line so that they can be easily changed

                解决方案

                You can do something like this:

                import sys
                from PIL import Image
                
                images = [Image.open(x) for x in ['Test1.jpg', 'Test2.jpg', 'Test3.jpg']]
                widths, heights = zip(*(i.size for i in images))
                
                total_width = sum(widths)
                max_height = max(heights)
                
                new_im = Image.new('RGB', (total_width, max_height))
                
                x_offset = 0
                for im in images:
                  new_im.paste(im, (x_offset,0))
                  x_offset += im.size[0]
                
                new_im.save('test.jpg')
                

                Test1.jpg

                Test2.jpg

                Test3.jpg

                test.jpg


                The nested for for i in xrange(0,444,95): is pasting each image 5 times, staggered 95 pixels apart. Each outer loop iteration pasting over the previous.

                for elem in list_im:
                  for i in xrange(0,444,95):
                    im=Image.open(elem)
                    new_im.paste(im, (i,0))
                  new_im.save('new_' + elem + '.jpg')
                

                这篇关于用 Python 水平组合多张图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                How to break out of multiple loops?(如何打破多个循环?)
                How to put the legend out of the plot(如何将传说从情节中剔除)
                Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                  <i id='RDehb'><tr id='RDehb'><dt id='RDehb'><q id='RDehb'><span id='RDehb'><b id='RDehb'><form id='RDehb'><ins id='RDehb'></ins><ul id='RDehb'></ul><sub id='RDehb'></sub></form><legend id='RDehb'></legend><bdo id='RDehb'><pre id='RDehb'><center id='RDehb'></center></pre></bdo></b><th id='RDehb'></th></span></q></dt></tr></i><div id='RDehb'><tfoot id='RDehb'></tfoot><dl id='RDehb'><fieldset id='RDehb'></fieldset></dl></div>
                  <legend id='RDehb'><style id='RDehb'><dir id='RDehb'><q id='RDehb'></q></dir></style></legend>
                      <bdo id='RDehb'></bdo><ul id='RDehb'></ul>
                      • <tfoot id='RDehb'></tfoot>
                      • <small id='RDehb'></small><noframes id='RDehb'>

                            <tbody id='RDehb'></tbody>