mobi.py 文件源码

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

项目:kmanga 作者: aplanas 项目源码 文件源码
def filter_footer(self, img):
        """Filter to remove the hight quality footer for an image."""
        # Some sites like MangaFox add an extra footer in the original
        # image.  This footer remove importan space in the Kindle, and
        # we need to remove it.
        #
        # The algorithm use as a leverage the normal noise present in
        # an scanned image, that is higher than the one in the footer.
        # This means that this filter will only work in medium quality
        # scanners, but possibly not in high quality ones.
        #
        # The process is like this:
        #
        #   1.- Binarize the image, moving the noise at the same level
        #       that the real information.
        #
        #   2.- Use a MinFilter of size 3 to a big mass of pixels that
        #       containg high frequency data.  That usually means
        #       pixels surrounded with blanks.
        #
        #   3.- Do a Gaussian filter to lower more the high frequency
        #       data, moving the mass close arround the pixel.  This
        #       will lower more the pixels surrounded with gaps.
        #
        #   4.- Discard the pixels with low mass.
        #
        _img = ImageOps.invert(img.convert(mode='L'))
        _img = _img.point(lambda x: x and 255)
        _img = _img.filter(ImageFilter.MinFilter(size=3))
        _img = _img.filter(ImageFilter.GaussianBlur(radius=5))
        _img = _img.point(lambda x: (x >= 48) and x)
        # If the image is white, we do not have bbox
        return img.crop(_img.getbbox()) if _img.getbbox() else img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号