예제 #1
0
파일: test.py 프로젝트: FUHannes/IVC
def generate_data(filename, version, block_size=16):
    input_path = os.path.join(PGM_ORIGINAL_PATH, filename + PGM_SUFFIX)

    if not os.path.exists(BITSTREAM_PATH):
        os.mkdir(BITSTREAM_PATH)
    bitstream_path = os.path.join(BITSTREAM_PATH, filename + BITSTREAM_SUFFIX)

    if not os.path.exists(PGM_RECONSTRUCTION_PATH):
        os.mkdir(PGM_RECONSTRUCTION_PATH)
    output_path = os.path.join(PGM_RECONSTRUCTION_PATH, filename + PGM_SUFFIX)

    df = pd.DataFrame(columns=['bpp', 'db'])

    for index, quality in enumerate([8, 12, 16, 20, 24]):
        enc = Encoder(input_path, bitstream_path, block_size, quality, False)
        enc.encode_image()
        dec = Decoder(bitstream_path, output_path, pgm=True)
        dec.decode_all_frames()

        process = subprocess.run(
            [PSNR_TOOL_PATH, input_path, output_path, bitstream_path],
            stdout=subprocess.PIPE,
        )

        stdout = process.stdout.decode("utf-8")
        bpp, db = stdout.split(' bpp ')
        bpp, db = float(bpp), float(db.replace(' dB', ''))
        db = 0.0 if math.isinf(db) else db
        df.loc[index] = [bpp, db]

    version_path = os.path.join(DATA_ROOT_PATH, version)
    print(version)
    if not os.path.exists(version_path):
        os.mkdir(version_path)
    df.to_pickle(os.path.join(version_path, filename + DATA_SUFFIX))
예제 #2
0
파일: decode.py 프로젝트: FUHannes/IVC
def main():
    parser = argparse.ArgumentParser(description='image/video decoder')
    parser.add_argument('-b',
                        '--bitstream',
                        help='bitstream file to be read by decoder',
                        required=True,
                        dest='bitstream')
    parser.add_argument('-o',
                        '--output',
                        help='reconstructed image or video',
                        required=True,
                        dest='output')
    parser.add_argument('-pgm',
                        help='if set write output as PGM image',
                        action='store_true',
                        dest='pgm')
    args = parser.parse_args()

    start_time = time.process_time()  # benchmarking speed
    dec = Decoder(args.bitstream, args.output, args.pgm)
    dec.decode_all_frames()
    decoding_time = time.process_time() - start_time
    print(f'it took {decoding_time * 1000} ms to decode')