ImageBuffer.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:nimo 作者: wolfram2012 项目源码 文件源码
def asStackBW(self, size=None):
        '''
        Outputs an image buffer as a 3D numpy array ("stack") of grayscale images.
        @param size: A tuple (w,h) indicating the output size of each frame.
        If None, then the size of the first image in the buffer will be used.
        @return: a 3D array (stack) of the gray scale version of the images
        in the buffer. The dimensions of the stack are (N,w,h), where N is
        the number of images (buffer size), w and h are the width and height
        of each image.        
        '''
        if size==None:
            img0 = self[0]        
            (w,h) = img0.size
        else:
            (w,h) = size

        f = self.getCount()
        stack = sp.zeros((f,w,h))
        for i,img in enumerate(self._data):
            #if img is not (w,h) in size, then resize first
            sz = img.size
            if (w,h) != sz:
                img2 = img.resize((w,h))
                mat = img2.asMatrix2D()
            else:
                mat = img.asMatrix2D()
            stack[i,:,:] = mat

        return stack
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号