mxrera / onas

Image codification tool
1 stars 0 forks source link

Transform blocks (DCT, KLT, FFT) #2

Open Yagouch opened 3 months ago

Yagouch commented 3 months ago

Helpful code

c = np.array([1, 2, 3, 4, 8, 16])
m = l3.define_zigzag_matrix(c)
rec_image = np.zeros(im2_gray.shape)

fig, axs = plt.subplots(2,3, figsize=(14,9))

for kk in range(6):
    title_recons = 'N={}'.format(c[kk])
    for ii in range(64):         #=0:63
        for jj in range (64):    #=0:63
            dct_image2 = dct_image[(ii*8):(ii*8+8),(jj*8):(jj*8+8)]
            rec_image[ii*8:ii*8+8,jj*8:jj*8+8] = idct2d(dct_image2 * m[kk,:,:]) + 128

    rec_image = np.round(rec_image).astype(np.uint8)
    PSNR1, _ = l3.mypsnr(im2_gray, rec_image)
    psnr = 'PSNR = {} dB'.format(np.round(PSNR1,2))

    gindx = kk %  3
    gindy = kk // 3
    axs[gindy,gindx].imshow(rec_image.astype(int), cmap='gray', vmin=0, vmax=255)
    if kk == 1:
        axs[gindy,gindx].set_title('ZIG-ZAG SCAN \n' + title_recons)
    else:
        axs[gindy,gindx].set_title(title_recons)
    axs[gindy,gindx].xaxis.set_ticks([])
    axs[gindy,gindx].yaxis.set_ticks([])
    axs[gindy,gindx].set_xlabel('{}'.format(psnr))

plt.show()