tools.py 文件源码

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

项目:lddmm-ot 作者: jeanfeydy 项目源码 文件源码
def _convert_to_RGB_255(colors):
        """
        Multiplies each element of a triplet by 255

        Each coordinate of the color tuple is rounded to the nearest float and
        then is turned into an integer. If a number is of the form x.5, then
        if x is odd, the number rounds up to (x+1). Otherwise, it rounds down
        to just x. This is the way rounding works in Python 3 and in current
        statistical analysis to avoid rounding bias
        """
        rgb_components = []

        for component in colors:
            rounded_num = decimal.Decimal(str(component*255.0)).quantize(
                decimal.Decimal('1'), rounding=decimal.ROUND_HALF_EVEN
            )
            # convert rounded number to an integer from 'Decimal' form
            rounded_num = int(rounded_num)
            rgb_components.append(rounded_num)

        return (rgb_components[0], rgb_components[1], rgb_components[2])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号