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 
Switch to threaded view of this topic Create a new topic Submit Reply
Where is the error in this DCT-approach? [message #68411] Tue, 27 October 2009 14:02 Go to next 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
Re: Where is the error in this DCT-approach? [message #68558 is a reply to message #68411] Tue, 03 November 2009 02:36 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
On 3 Nov., 00:44, pp <pp.pente...@gmail.com> wrote:
> On Nov 2, 9:27 pm, chris <rog...@googlemail.com> wrote:
>
>> Does nobody have any idea?
>
>> :(
>
>> CR
>
> You should at least describe the problem before expecting an answer.
> Not many people will try to interpret a page of code just to try to
> guess what problem you may have.

Ok, that's right. Thank you. The problem is that a forward followed by
a backward transformation of, for instance, a "dist"-image shows only
a simple cross and not the "dist"-image again. I cannot understand,
why the code won't work as expected. Please help me!

Thanks and best regards

CR
Re: Where is the error in this DCT-approach? [message #68561 is a reply to message #68411] Mon, 02 November 2009 15:44 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Nov 2, 9:27 pm, chris <rog...@googlemail.com> wrote:
> Does nobody have any idea?
>
> :(
>
> CR

You should at least describe the problem before expecting an answer.
Not many people will try to interpret a page of code just to try to
guess what problem you may have.
Re: Where is the error in this DCT-approach? [message #68562 is a reply to message #68411] Mon, 02 November 2009 15:27 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
Does nobody have any idea?

:(

CR
  Switch to threaded view of this topic Create a new topic Submit Reply
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 17:11:56 PDT 2025

Total time taken to generate the page: 0.00475 seconds