Skip to content

Instantly share code, notes, and snippets.

@ginrou
Last active August 14, 2023 09:27
Show Gist options
  • Save ginrou/5e443b42aabe73664b41 to your computer and use it in GitHub Desktop.
Save ginrou/5e443b42aabe73664b41 to your computer and use it in GitHub Desktop.
DCTでlennaを再構成する
#!/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