Last active
August 14, 2023 09:27
-
-
Save ginrou/5e443b42aabe73664b41 to your computer and use it in GitHub Desktop.
DCTでlennaを再構成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import numpy as np | |
import scipy.misc | |
from scipy.fftpack import dct, idct | |
import sys | |
H = 128 | |
W = 128 | |
lenna = scipy.misc.imresize(scipy.misc.lena(), (H, W)).astype(float) | |
lenna_F = dct(dct(lenna, axis=0), axis=1) ## 2D DCT of lenna | |
canvas = np.zeros((H,W)) | |
for h in range(H): | |
for w in range(W): | |
a = np.zeros((H,W)) | |
a[h,w] = 1 | |
base = idct(idct(a, axis=0), axis=1) ## create dct bases | |
canvas += lenna_F[h,w] * base ## accumulate | |
scipy.misc.imsave("base-%03d-%03d.png" % (h, w), base) | |
scipy.misc.imsave("lenna-%03d-%03d.png" % (h, w), canvas) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment