def get_msssim():
    bppl = []
    ssim = []
    namel = []
    path = '/mnt/Volume1/test/clic2020-devkit/bpg_reslut'
    path_ta = '/mnt/Volume1/test/clic2020-devkit/targets_yuv'
    path_bpg = '/mnt/Volume1/test/clic2020-devkit/part_bpg'
    for root, dirs, files in os.walk(path, topdown=False):
        for name in files:
            #get size
            p = os.path.join(path_bpg, name.replace('.png', '.bpg'))
            size = os.path.getsize(p)
            fig1 = Image.open(os.path.join(root, name))
            fig1_array = np.asarray(fig1)
            fig2 = Image.open(os.path.join(path_ta, name))
            fig2_array = np.asarray(fig2)

            bpp = size * 8 / fig1.size[0] / fig1.size[1]
            #fig2 = Image.open('/mnt/Volume0/test/1.png')
            fig1_array = fig1_array.reshape(
                (1, fig1_array.shape[0], fig1_array.shape[1], 1))
            fig2_array = fig2_array.reshape(
                (1, fig2_array.shape[0], fig2_array.shape[1], 1))

            # yuv = np.concatenate([fig1_array,fig1_array,fig1_array], axis = 3)
            # yuv1 = np.concatenate([fig2_array,fig2_array,fig2_array], axis = 3)
            score = MultiScaleSSIM(fig1_array,
                                   fig2_array,
                                   max_val=255,
                                   filter_size=11,
                                   filter_sigma=1.5,
                                   k1=0.01,
                                   k2=0.03,
                                   weights=None)
            print(score)
            bppl.append(bpp)
            ssim.append(score)
            namel.append(name)
    df1 = pd.DataFrame({'name': namel})
    df2 = pd.DataFrame({'bpp': bppl})
    df3 = pd.DataFrame({'ssim': ssim})
    writer = pd.ExcelWriter(
        '/mnt/Volume1/test/clic2020-devkit/bpg_bpp_ssim.xlsx')

    df1.to_excel(writer, sheet_name='name', startcol=0)
    df2.to_excel(writer, sheet_name='bpp', startcol=1)
    df3.to_excel(writer, sheet_name='ssim', startcol=2)

    writer.save()
Ejemplo n.º 2
0
def encode_I(args, frame_index, I_level, path, path_com, path_bin):

    if args.mode == 'PSNR':
        os.system('bpgenc -f 444 -m 9 ' + path + 'f' +
                  str(frame_index).zfill(3) + '.png '
                  '-o ' + path_bin + 'f' + str(frame_index).zfill(3) +
                  '.bin -q ' + str(I_level))
        os.system('bpgdec ' + path_bin + 'f' + str(frame_index).zfill(3) +
                  '.bin '
                  '-o ' + path_com + 'f' + str(frame_index).zfill(3) + '.png')

    elif args.mode == 'MS-SSIM':
        os.system(args.python_path + ' ' + args.CA_model_path +
                  '/encode.py --model_type 1 '
                  '--input_path ' + path + 'f' + str(frame_index).zfill(3) +
                  '.png' + ' --compressed_file_path ' + path_bin + 'f' +
                  str(frame_index).zfill(3) + '.bin' + ' --quality_level ' +
                  str(I_level))
        os.system(args.python_path + ' ' + args.CA_model_path +
                  '/decode.py --compressed_file_path ' + path_bin + 'f' +
                  str(frame_index).zfill(3) + '.bin' + ' --recon_path ' +
                  path_com + 'f' + str(frame_index).zfill(3) + '.png')

    # bits = os.path.getsize(path_bin + str(frame_index).zfill(3) + '.bin')
    # bits = bits * 8

    F0_com = misc.imread(path_com + 'f' + str(frame_index).zfill(3) + '.png')
    F0_raw = misc.imread(path + 'f' + str(frame_index).zfill(3) + '.png')

    F0_com = np.expand_dims(F0_com, axis=0)
    F0_raw = np.expand_dims(F0_raw, axis=0)

    if args.metric == 'PSNR':
        mse = np.mean(
            np.power(np.subtract(F0_com / 255.0, F0_raw / 255.0), 2.0))
        quality = 10 * np.log10(1.0 / mse)
    elif args.metric == 'MS-SSIM':
        quality = MultiScaleSSIM(F0_com, F0_raw, max_val=255)

    print('Frame', frame_index, args.metric + ' =', quality)

    return quality
Ejemplo n.º 3
0
 def get_msssim():
     return MultiScaleSSIM(make_batched(inp_img), make_batched(out_img))
Ejemplo n.º 4
0
def compare_msssim(inp_img_batched, out_img_batched):
    return MultiScaleSSIM(inp_img_batched, out_img_batched)
         
        str_file_target = os.path.join("/mnt/Volume1/test/clic2020-devkit/yuv_result",name)
        str_mid =os.path.join('/mnt/Volume1/test/clic2020-devkit/tng_save',name[:-5]+'rgb.tng')

        im_re = Image.open(str_file_result)
        im_ta = Image.open(str_file_target)

        im_re_arr = np.asarray(im_re)
        im_ta_arr = np.asarray(im_ta)

        im_re_arr = im_re_arr.reshape((1,im_re_arr.shape[0],im_re_arr.shape[1],1))
        im_ta_arr = im_ta_arr.reshape((1,im_ta_arr.shape[0],im_ta_arr.shape[1],1))
        
        yuv = np.concatenate([im_re_arr,im_re_arr,im_re_arr], axis = 3)
        yuv1 = np.concatenate([im_ta_arr,im_ta_arr,im_ta_arr], axis = 3)
        score = MultiScaleSSIM(yuv,yuv1)
        if np.isnan(score):
            print(str_file_result)
            score = 0
        #print(score)
        #str_w = 'input:' + p2+'; '+ 'target: ' + name + '; ' + 'ssim: ' + str(score)+ '\n'
        
        score_nochange = float(data[i].split(':',4)[3]) 
        ssims[i%3]=score_nochange
        size = os.path.getsize(str_mid)
        #print("size",size)
        if not (i+1)%3:
            tmp = tmp + size
            ssim_tng = ssim_tng + score * 4
            ssim_yuv = ssim_yuv + score_nochange*4
            # print("tng",ssim_tng)
Ejemplo n.º 6
0
              str(I_level))
    os.system(args.python_path + ' ' + args.CA_model_path +
              '/decode.py --compressed_file_path ' + path_com +
              str(f + 1).zfill(3) + '.bin' + ' --recon_path ' + path_com +
              'f' + str(f + 1).zfill(3) + '.png')

F0_com = misc.imread(path_com + 'f' + str(f + 1).zfill(3) + '.png')
F0_raw = misc.imread(path + 'f' + str(f + 1).zfill(3) + '.png')

#Quality(to WRQE)
if args.mode == 'PSNR':
    mse = np.mean(np.power(np.subtract(F0_com / 255.0, F0_raw / 255.0), 2.0))
    quality_frame[f] = 10 * np.log10(1.0 / mse)
elif args.mode == 'MS-SSIM':
    quality_frame[f] = MultiScaleSSIM(np.expand_dims(F0_com, 0),
                                      np.expand_dims(F0_raw, 0),
                                      max_val=255)

with open(path_com + 'quality_' + str(f + 1).zfill(3) + '.bin', "wb") as ff:
    ff.write(np.array(quality_frame[f], dtype=np.float32).tobytes())

bits = os.path.getsize(path_com + str(f + 1).zfill(3) + '.bin') \
       + os.path.getsize(path_com + 'quality_' + str(f + 1).zfill(3) + '.bin')

bits = bits * 8

#Bits(to WRQE)
bits_frame[f] = bits / Height / Width
print('Frame', f + 1)
print(args.mode + ' =', quality_frame[f], 'bpp =', bits_frame[f])
Ejemplo n.º 7
0
    bits = os.path.getsize(path_bin + str(f + 1).zfill(3) + '.bin')
    bits = bits * 8

    F0_com = misc.imread(path_com + 'f' + str(f + 1).zfill(3) + '.png')
    F0_raw = misc.imread(path + 'f' + str(f + 1).zfill(3) + '.png')

    F0_com = np.expand_dims(F0_com, axis=0)
    F0_raw = np.expand_dims(F0_raw, axis=0)

    if args.metric == 'PSNR':
        mse = np.mean(
            np.power(np.subtract(F0_com / 255.0, F0_raw / 255.0), 2.0))
        quality_frame[f] = 10 * np.log10(1.0 / mse)
    elif args.metric == 'MS-SSIM':
        quality_frame[f] = MultiScaleSSIM(F0_com, F0_raw, max_val=255)

    bits_frame[f] = bits
    print('Frame', f + 1, args.metric + ' =', quality_frame[f], 'bpp =',
          bits_frame[f] / Height / Width)

    p_frame_number = np.min([args.GOP - 1, args.frame - f - 1])

    for p_frame in range(p_frame_number):

        f = f + 1

        F1_raw = misc.imread(path + 'f' + str(f + 1).zfill(3) + '.png')
        F1_raw = np.expand_dims(F1_raw, axis=0)

        F0_com, string_MV, string_Res, quality_com \