def run_implementation(block_size, implementation, image_filename, filterbank_filename, res_filename_prefix): ''' Execution wrapper ''' from blip.simulator import interpreter from blip.support import imageio # first load the cascade filterbank = Filterbank.load(filterbank_filename) image = imageio.read(image_filename) if not image: raise Exception('image %s not found or not supported'%image_filename) im_size = len(image[0]), len(image) pe_dim = [s//b for s,b in zip(im_size, block_size)] args = {'filterbank':filterbank, 'pe_dim':pe_dim} # now execute the codegen code = Code() code.set_generator(implementation, block_size, args) sim = interpreter.Interpreter(code, image, block_size, 4) sim.run() result = sim.gen_output_image(1) # result is saved in first buffer imageio.write(res_filename_prefix + '.png', result, 1)
def main(filtersfile, inputimage, outputimage): ''' Main entry function. ''' filterbank = Filterbank.load(filtersfile) filters = filterbank.filters inputimage = imageio.read(inputimage) output = calc_planarity(inputimage, filters) output = _scale_to_integer(output) imageio.write(outputimage, output, 1)
def _test_gen_calc_impl(codegen_impl): from planarity.reference import calc_planarity rows, cols = 32, 64 image = gen_random_image(rows, cols) filterbank_filename = '../data/asym_16_3_opencv.xml' filterbank = Filterbank.load(filterbank_filename) test_res, _ = run_codegen_function(image, codegen_impl, block_size, {'filterbank':filterbank}, 1) ref_res = calc_planarity(image, filterbank.filters) assert ref_res == test_res
def default_argument_setup(filterbank_filename='data/asym_16_3_opencv.xml'): filterbank = Filterbank.load(filterbank_filename) return {'filterbank':filterbank}