image.py 文件源码

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

项目:marblecutter 作者: mojodna 项目源码 文件源码
def transform(self, pixels):
        data = pixels.data
        (count, height, width) = data.shape

        if 3 > count > 4:
            raise Exception("Source data must be 3 or 4 bands")

        if count == 4:
            raise Exception(
                "Variable opacity (alpha channel) not yet implemented")

        data *= np.iinfo(np.uint8).max

        rgb = np.ma.transpose(data.astype(np.uint8), [1, 2, 0])
        if data.mask.any():
            a = np.logical_and.reduce(~data.mask).astype(np.uint8) * 255
        else:
            a = np.full((rgb.shape[:-1]), 255, np.uint8)

            # Nearblack filtering for collar removal--partial, as edge values
            # will have been resampled in such a way that they don't retain
            # their crispness.
            # See https://stackoverflow.com/a/22631583 for neighborhood
            # filtering
            # sums = np.add.reduce(data)
            # threshold = 64
            # a = np.logical_and(sums > threshold, sums <
            #                    (255 * 3) - threshold).astype(np.uint8) * 255

        return PixelCollection(np.dstack((rgb, a)), pixels.bounds), 'RGBA'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号