Created
February 13, 2011 07:01
-
-
Save justjkk/824509 to your computer and use it in GitHub Desktop.
Discrete Cosine Transformation in python using FP
This file contains hidden or 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
| from math import cos | |
| PI = 3.141592 | |
| N = 8 | |
| def f(u,v): | |
| if u + v % 2: return 0 | |
| return 1 | |
| def sum(x,y): | |
| return x + y | |
| def sigma(r,f): | |
| return reduce(sum, map(f,r)) | |
| def C(u): | |
| if u == 0: return 2**-0.5 | |
| return 1.0 | |
| def F(u,v): | |
| return round((C(u) * C(v) / 4) * sigma(range(N), lambda i: sigma(range(N), lambda j: cos((2 * i + 1) * u * PI / (2 * N)) * cos((2 * j + 1) * v * PI / (2 * N)) * f(i,j))),2) | |
| def dct(): | |
| return map(lambda u: map(lambda v: F(u,v), range(N)), range(N)) | |
| print dct() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment