Created
April 9, 2017 21:56
-
-
Save mandykoh/a4d01fb16ded0c17bff491d9cda217ee to your computer and use it in GitHub Desktop.
Generalised 2D Type-II DCT for MxN matrix
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
package dct | |
import "math" | |
func DCT(width int, height int, values []float64) (result []float64) { | |
doubleWidth := 2.0 * float64(width) | |
doubleHeight := 2.0 * float64(height) | |
result = make([]float64, len(values)) | |
for u := 0; u < height; u++ { | |
for v := 0; v < width; v++ { | |
sum := 0.0 | |
for i := 0; i < height; i++ { | |
for j := 0; j < width; j++ { | |
sum += float64(values[i*width+j]) * | |
math.Cos(((math.Pi*float64(u))/doubleHeight)*(2*float64(i)+1)) * | |
math.Cos(((math.Pi*float64(v))/doubleWidth)*(2*float64(j)+1)) | |
} | |
} | |
result[u*width+v] = sum | |
} | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment