comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Where is the error in this DCT-approach?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Where is the error in this DCT-approach? [message #68411] Tue, 27 October 2009 14:02 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
Hi there,
I cant find the error in this little program to compute forward and
backward the discrete cosine transform of an image. It seems to be
also difficult to avoid the loops. Please help me. Here is the code:

function cr_dct,dat,mode,shiftit=shiftit

sz = size(dat,/dimensions)
dim = n_elements(sz)
mode = n_elements(mode) eq 0? -1 : -2>mode<2
shiftit = keyword_set(shiftit)? 1 : 0

case dim of

1 : begin

end
2: begin
x = sz[0]
y = sz[1]
c = fltarr(sz)
sqrtx = sqrt(x)
sqrty = sqrt(y)
sqrt2 = sqrt(2)
sqrt2x = sqrt2/sqrtx
sqrt2y = sqrt2/sqrty
arr = c
indarr = (((l=findgen(x>y)))#(2.*l+1))*!dtor
cosxarr = cos(indarr/(2.*x))
cosyarr = x eq y? cosxarr : cos(indarr/(2.*y))
for u=0,x-1 do begin
for v=0,y-1 do begin
alphau = u eq 0 ? sqrtx : sqrt2x
alphav = v eq 0 ? sqrty : sqrt2y
tmparr = arr
;tmparr=dat*((r=rebin(cosxarr[u,*],x,y))) * $
; (x eq y? r: rebin(cosyarr[v,*],x,y))
;tmparr=(dat)[*] * ((r=(rebin(cosxarr[u,*],x,y))[*])) * $
; (x eq y? r : (rebin(cosxarr[v,*],x,y))[*])

for i=0,x-1 do $
for j=0,y-1 do $
tmparr[i,j] = mode eq -1? $
dat[i,j]*cosxarr[u,i]*cosyarr[v,j] : $
alphau*alphav*dat[i,j]*cosxarr[u,i]*cosyarr[v,j]
c[u,v] = mode eq -1? total(tmparr)*alphau*alphav : total(tmparr)

endfor
endfor
c = shiftit? shift(c,long(x/2),long(y/2)) : c

end

endcase
print,mode
return,c
end

pro test_dct
test=dist(16)
tvscl,congrid(test,128,128),0
tvscl, congrid(cr_dct(cr_dct(test,-1,/shiftit),1,/shiftit),128,128) ,1
end

Thank you and best regards

CR
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: writing large 3D data file fails
Next Topic: How 2 import some data to a widget!!

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:17:01 PDT 2025

Total time taken to generate the page: 0.00429 seconds