Ejemplo n.º 1
0
 def test_9x9_linear_reduce(self):
     res = {
         'weights': [0.2270270, 0.3162162, 0.0702702],
         'offsets': [0, 1.3846153, 3.2307692]
     }
     this = kernel_binom_linear(kernel_binom(9, 2, 2))
     self._compare_linear(res, this)
Ejemplo n.º 2
0
 def test_9x9_reduce(self):
     res = {
         'weights': [0.2270270, 0.1945945, 0.1216216, 0.0540540, 0.0162162],
         'offsets': [0, 1, 2, 3, 4]
     }
     this = kernel_binom(9, 2, 2)
     self._compare(res, this)
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser(
        description="Calculates gaussian kernel weights and offsets from a "
        "binomial distribution and optionally adjust the weights "
        "and offsets for a linearly-sampled gaussian blur shader.")

    parser.add_argument("taps",
                        default=5,
                        type=int,
                        help="Specify the number of taps (kernel size)")

    parser.add_argument(
        "--expand",
        default=0,
        type=int,
        help="How much to expand the tap count (expand outermost "
        "coefficients)")

    parser.add_argument(
        "--reduce",
        default=0,
        type=int,
        help="How many taps to discard at borders (eliminate outermost "
        "coefficients)")

    parser.add_argument(
        "--linear",
        default=False,
        action='store_true',
        help="Uses linear sampling to compute weights and offsets")

    args = parser.parse_args()

    taps = args.taps
    exp = args.expand
    red = args.reduce
    linear = args.linear

    print "Computing a", \
        bold("{0}-tap".format(taps)), \
        "filter kernel (+%(exp)s/-%(red)s) %(desc)s" % \
        {
            'taps': taps,
            'exp': exp * 2,
            'red': red * 2,
            'desc': " (+linear reduction)" if linear else ""
        }

    print "Initial gaussian distribution: {0}".format(
        bold(str(binom(taps - 1 + exp * 2))))

    ntap = taps

    res_discrete = kernel_binom(taps, exp, red)
    res_linear = None

    if linear:
        res_linear = kernel_binom_linear(res_discrete)
        ntap = (len(res_linear['weights']) * 2) - 1

    if res_discrete is not None:
        float_format = "{:.8f}"

        print "Initial ", \
            bold("{0}-tap".format(taps)), \
            "filter kernel coefficients:".format(taps)

        print "\tweights:", \
            [float_format.format(x) for x in res_discrete["weights"]]

        print "\toffsets:", \
            [float_format.format(x) for x in res_discrete["offsets"]]

        if linear and res_linear is not None:
            print "\nOptimized", \
                bold("{0}-tap".format(ntap)), \
                "filter kernel coefficients:".format(ntap)
            print "\tweights:", \
                [float_format.format(x) for x in res_linear["weights"]]

            print "\toffsets:", \
                [float_format.format(x) for x in res_linear["offsets"]]
Ejemplo n.º 4
0
 def test_9x9_linear_reduce(self):
     res = {'weights': [0.2270270, 0.3162162, 0.0702702],
            'offsets': [0, 1.3846153, 3.2307692]}
     this = kernel_binom_linear(kernel_binom(9, 2, 2))
     self._compare_linear(res, this)
Ejemplo n.º 5
0
 def test_9x9_reduce(self):
     res = {
         'weights': [0.2270270, 0.1945945, 0.1216216, 0.0540540, 0.0162162],
         'offsets': [0, 1, 2, 3, 4]}
     this = kernel_binom(9, 2, 2)
     self._compare(res, this)
Ejemplo n.º 6
0
    def test_5x5_linear(self):
        res = {'weights': [0.375, 0.3125],
               'offsets': [0, 1.2]}

        this = kernel_binom_linear(kernel_binom(5, 0, 0))
        self._compare_linear(res, this)
Ejemplo n.º 7
0
 def test_5x5(self):
     res = {'weights': [0.375, 0.25, 0.0625],
            'offsets': [0, 1, 2]}
     this = kernel_binom(5, 0, 0)
     self._compare(res, this)
Ejemplo n.º 8
0
 def test_3x3(self):
     res = {'weights': [0.5, 0.25],
            'offsets': [0, 1]}
     this = kernel_binom(3, 0, 0)
     self._compare(res, this)
Ejemplo n.º 9
0
    def test_5x5_linear(self):
        res = {'weights': [0.375, 0.3125], 'offsets': [0, 1.2]}

        this = kernel_binom_linear(kernel_binom(5, 0, 0))
        self._compare_linear(res, this)
Ejemplo n.º 10
0
 def test_5x5(self):
     res = {'weights': [0.375, 0.25, 0.0625], 'offsets': [0, 1, 2]}
     this = kernel_binom(5, 0, 0)
     self._compare(res, this)
Ejemplo n.º 11
0
 def test_3x3(self):
     res = {'weights': [0.5, 0.25], 'offsets': [0, 1]}
     this = kernel_binom(3, 0, 0)
     self._compare(res, this)
Ejemplo n.º 12
0
def main():
    parser = argparse.ArgumentParser(
        description="Calculates gaussian kernel weights and offsets from a "
                    "binomial distribution and optionally adjust the weights "
                    "and offsets for a linearly-sampled gaussian blur shader.")

    parser.add_argument(
        "taps", default=5, type=int,
        help="Specify the number of taps (kernel size)"
    )

    parser.add_argument(
        "--expand", default=0, type=int,
        help="How much to expand the tap count (expand outermost "
             "coefficients)"
    )

    parser.add_argument(
        "--reduce", default=0, type=int,
        help="How many taps to discard at borders (eliminate outermost "
             "coefficients)"
    )

    parser.add_argument(
        "--linear", default=False, action='store_true',
        help="Uses linear sampling to compute weights and offsets"
    )

    args = parser.parse_args()

    taps = args.taps
    exp = args.expand
    red = args.reduce
    linear = args.linear

    print "Computing a", \
        bold("{0}-tap".format(taps)), \
        "filter kernel (+%(exp)s/-%(red)s) %(desc)s" % \
        {
            'taps': taps,
            'exp': exp * 2,
            'red': red * 2,
            'desc': " (+linear reduction)" if linear else ""
        }

    print "Initial gaussian distribution: {0}".format(
        bold(str(binom(taps - 1 + exp * 2)))
    )

    ntap = taps

    res_discrete = kernel_binom(taps, exp, red)
    res_linear = None

    if linear:
        res_linear = kernel_binom_linear(res_discrete)
        ntap = (len(res_linear['weights']) * 2) - 1

    if res_discrete is not None:
        float_format = "{:.8f}"

        print "Initial ", \
            bold("{0}-tap".format(taps)), \
            "filter kernel coefficients:".format(taps)

        print "\tweights:", \
            [float_format.format(x) for x in res_discrete["weights"]]

        print "\toffsets:", \
            [float_format.format(x) for x in res_discrete["offsets"]]

        if linear and res_linear is not None:
            print "\nOptimized", \
                bold("{0}-tap".format(ntap)), \
                "filter kernel coefficients:".format(ntap)
            print "\tweights:", \
                [float_format.format(x) for x in res_linear["weights"]]

            print "\toffsets:", \
                [float_format.format(x) for x in res_linear["offsets"]]