__init__.py 文件源码

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

项目:HTM_experiments 作者: ctrl-z-9000-times 项目源码 文件源码
def _fix_alpha_channel(self):
        # This is a fix for a bug where the Alpha channel was dropped.
        colors3to4 = [(c[:3], c[3]) for c in self.names.keys()]
        colors3to4 = dict(colors3to4)
        assert(len(colors3to4) == len(self.names)) # Dropped alpha channel causes colors to collide :(
        for lbl in self.labels:
            if lbl is None:
                continue    # No label file created yet.
            img  = Image.open(lbl)
            size = img.size
            img  = np.array(img)
            if img.shape[2] == 4:
                continue    # Image has alpha channel, good.
            elif img.shape[2] == 3:
                # Lookup each (partial) color and find what its alpha should be.
                alpha   = np.apply_along_axis(lambda c: colors3to4[tuple(c)], 2, img)
                data    = np.dstack([img, np.array(alpha, dtype=np.uint8)])
                new_img = Image.frombuffer("RGBA", size, data, "raw", "RGBA", 0, 1)
                new_img.save(lbl)
                print("FIXED", lbl)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号