wikipedia: https://en.wikipedia.org/wiki/Discrete_cosine_transform
video=>https://greencoin.life/how-to/calculate/dct-coefficients-with-example/CAn-FzQkGTA <= not the best video but hey!
i've split up the exp to try and debug it and for now it seems that the issue is somewhere before the Cos() function, no matter what value it passes to cos() it returns 0
this is the code i have for now
Code: Select all
; Generate DCT Matrix of Size NxN
pi := 3.141592653589793
; c = (c(k,n)) ; k=Rows , n=columns
; K := 4 ; rows
; N := 4 ; cols
; if (k=0)
; C := 1/Sqrt(N)
; if (k>=1)
; C := Sqrt( 2/N ) * cos(((pi*((2*n)+1))*K) / ( 2*N ) )
K_Rows := 4
N_cols := 4
2d := []
loop % K_Rows
{
k:=A_index-1
loop % N_cols
{
n:=A_index-1
if (k=0)
{
2d[k,n] := 1/Sqrt(N_cols)
}
else if (k>=1)
{
a:= 2/N_cols
;msgbox % "a=" a
b:= 2*n
;msgbox % "b=" b
c:= b+1
;msgbox % "c=" c
d:= c*pi
;msgbox % "d=" d
e:= d * K_Rows
;msgbox % "e=" e
f:= 2*N_cols
;msgbox % "f=" f
g:= Sqrt( a )
;msgbox % "g=" g
h := e / f
;msgbox % "h=" h
i:= cos( h )
msgbox % "i=" i
value := g * i
;msgbox % "value=" value
2d[k,n] := value
; 2d[k,n] := Sqrt( 2/N_cols ) * cos( ( ( pi * ( (2*n) +1 ) ) * K_Rows ) / ( 2*N_cols ) )
}
}
}
stringArray := "["
for key,val in 2d
{
for i, v in val
{
stringArray .= v ","
}
StringTrimRight, stringArray,stringArray, 1
stringArray .= "`n"
}
StringTrimRight, stringArray,stringArray, 1
stringArray .= "]"
msgbox % stringArray
Im hoping to use the discrete cosine transformation to extract the frequency of an image
hopefully one of you can help spot my mistake