Esempio n. 1
0
    def run_test(images, th, alpha, block_size):
        image0 = images[0]
        im_size = len(image0)
        bwidth, bheight = block_size
        assert(im_size == bwidth * bheight) # only one pe

        code = Code()
        code.set_generator(gen_bbs, block_size, {'th':th, 'alpha':alpha})

        output = []
        sim = None
        for im in images:
            # interpreter expects 2D array
            im_tr = [[im[i*width + j] for j in xrange(bwidth)] for i in xrange(bheight)]
            if not sim:
                sim = Interpreter(code, im_tr, block_size)
            else:
                # restart code gen
                sim.reset()
                # set new image
                sim.set_src_image(im_tr)
            sim.run()
            im_out = sim.gen_output_image(1)
            # convert to 1D vector
            im_out_1D = []
            for row in im_out:
                for v in row:
                    im_out_1D.append(v)
            output.append(im_out_1D)
        return output