Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st February 2009, 23:38   #1  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
Wavelet lifting decomposition implemented in avisynth, rounding errors

I have implemented a linear prediction, linear filtering wavelet decomposition in avisynth. It is severely limited, but I implemented it mostly to try to get a better understanding of wavelet lifting, so this is not a problem I plan on fixing soon. It is however suffering from rounding and/or truncation errors, (rounding should be fixable, truncation is probably unfixable working within 8 bit colorspaces) Which I would Like to fix, my best guess is that the rounding errors are from the average plugin, or mt_lutxy, since it uses floats, however I am a bit confused, since as long as the rounding is deterministic, lifting should ensure that it does not result in errors in the decomposition. There is also a chrominance shift, which is most likely a problem with one of the mt_ functions.

The WaveletTest function will work on any yv12 input less then 1024*1024, and greater then 8*8, but for usefull results video should be between 256*256 and 1024*1024.

Code:
function afrb(clip c){ return(assumeframebased(c)) }
function afib(clip c){ return(assumefieldbased(c)) }

function wavelet_2_2_lifting_transform_1d_1_decomposition(clip c){

	c = c.assumetff().afrb

	Even = c.separatefields().selecteven()
	Odd = c.separatefields().selectodd()
	
	Prediction = average(Even, 0.5, Even.pointresize(Even.width, Even.height, 0, -1, Even.width, Even.height), 0.5)
	
	Odd_Coeficients = Mt_MakeDiff(Odd, Prediction, u=3, v=3)

	Update = average(Odd_Coeficients, 0.5, Odd_Coeficients.pointresize(Odd_Coeficients.width, Odd_Coeficients.height, 0, 1, Odd_Coeficients.width, Odd_Coeficients.height), 0.5)

	Smoothed_Even = Mt_LutXY(Even, Update, " y 128 - 0.5 * x + ", u=3, v=3)

	interleave(Smoothed_Even, Odd_Coeficients)
} function wt(clip c){ c.wavelet_2_2_lifting_transform_1d_1_decomposition() }



function inverse_wavelet_2_2_lifting_transform_1d_1_decomposition(clip Even, clip Odd_Coeficients){

	Update = average(Odd_Coeficients, 0.5, Odd_Coeficients.pointresize(Odd_Coeficients.width, Odd_Coeficients.height, 0, 1, Odd_Coeficients.width, Odd_Coeficients.height), 0.5)

	Even = Mt_LutXY(Even, Update, " x y 128 - 0.5 * - ", u=3, v=3)

	Prediction = average(Even, 0.5, Even.pointresize(Even.width, Even.height, 0, -1, Even.width, Even.height), 0.5)

	Odd = mt_adddiff(Prediction, Odd_Coeficients, u=3, v=3)

	interleave(Even, Odd).afib().weave()
} function iwt(clip Even, clip Odd_Coeficients){ inverse_wavelet_2_2_lifting_transform_1d_1_decomposition(Even, Odd_Coeficients) }


function WaveletTest(clip c, int "thresh"){

thresh = default(thresh, 4)
W = c.width
H = c.height
c = c.addborders(1024 - W, 1024 - H, 0, 0)


	DeompositionH1 = c.WT
		EvenH1 = DeompositionH1.selecteven()
		CoeficientsH1 = DeompositionH1.selectodd().Mt_lut( " X 128 - abs "+string(thresh/1)+" <= 128 x ? ", u=3, v=3)

	DeompositionW1 = EvenH1.turnright.WT
		EvenW1 = DeompositionW1.selecteven()
		CoeficientsW1 = DeompositionW1.selectodd().Mt_lut( " X 128 - abs "+string(thresh/1)+" <= 128 x ? ", u=3, v=3)

	DeompositionH2 = EvenW1.turnleft.WT
		EvenH2 = DeompositionH2.selecteven()
		CoeficientsH2 = DeompositionH2.selectodd().Mt_lut( " X 128 - abs "+string(thresh/2)+" <= 128 x ? ", u=3, v=3)

	DeompositionW2 = EvenH2.turnright.WT
		EvenW2 = DeompositionW2.selecteven()
		CoeficientsW2 = DeompositionW2.selectodd().Mt_lut( " X 128 - abs "+string(thresh/2)+" <= 128 x ? ", u=3, v=3)

	DeompositionH3 = EvenW2.turnleft.WT
		EvenH3 = DeompositionH3.selecteven()
		CoeficientsH3 = DeompositionH3.selectodd().Mt_lut( " X 128 - abs "+string(thresh/3)+" <= 128 x ? ", u=3, v=3)

	DeompositionW3 = EvenH3.turnright.WT
		EvenW3 = DeompositionW3.selecteven()
		CoeficientsW3 = DeompositionW3.selectodd().Mt_lut( " X 128 - abs "+string(thresh/3)+" <= 128 x ? ", u=3, v=3)

	DeompositionH4 = EvenW3.turnleft.WT
		EvenH4 = DeompositionH4.selecteven()
		CoeficientsH4 = DeompositionH4.selectodd().Mt_lut( " X 128 - abs "+string(thresh/4)+" <= 128 x ? ", u=3, v=3)

	DeompositionW4 = EvenH4.turnright.WT
		EvenW4 = DeompositionW4.selecteven()
		CoeficientsW4 = DeompositionW4.selectodd().Mt_lut( " X 128 - abs "+string(thresh/4)+" <= 128 x ? ", u=3, v=3)

	DeompositionH5 = EvenW4.turnleft.WT
		EvenH5 = DeompositionH5.selecteven()
		CoeficientsH5 = DeompositionH5.selectodd().Mt_lut( " X 128 - abs "+string(thresh/5)+" <= 128 x ? ", u=3, v=3)

	DeompositionW5 = EvenH5.turnright.WT
		EvenW5 = DeompositionW5.selecteven()
		CoeficientsW5 = DeompositionW5.selectodd().Mt_lut( " X 128 - abs "+string(thresh/5)+" <= 128 x ? ", u=3, v=3)

	DeompositionH6 = EvenW5.turnleft.WT
		EvenH6 = DeompositionH6.selecteven()
		CoeficientsH6 = DeompositionH6.selectodd().Mt_lut( " X 128 - abs "+string(thresh/6)+" <= 128 x ? ", u=3, v=3)

	DeompositionW6 = EvenH6.turnright.WT
		EvenW6 = DeompositionW6.selecteven()
		CoeficientsW6 = DeompositionW6.selectodd().Mt_lut( " X 128 - abs "+string(thresh/6)+" <= 128 x ? ", u=3, v=3)

	DeompositionH7 = EvenW6.turnleft.WT
		EvenH7 = DeompositionH7.selecteven()
		CoeficientsH7 = DeompositionH7.selectodd().Mt_lut( " X 128 - abs "+string(thresh/7)+" <= 128 x ? ", u=3, v=3)

	DeompositionW7 = EvenH7.turnright.WT
		EvenW7 = DeompositionW7.selecteven()
		CoeficientsW7 = DeompositionW7.selectodd().Mt_lut( " X 128 - abs "+string(thresh/7)+" <= 128 x ? ", u=3, v=3)

	DeompositionH8 = EvenW7.turnleft.WT
		EvenH8 = DeompositionH8.selecteven()
		CoeficientsH8 = DeompositionH8.selectodd().Mt_lut( " X 128 - abs "+string(thresh/8)+" <= 128 x ? ", u=3, v=3)

	DeompositionW8 = EvenH8.turnright.WT
		EvenW8 = DeompositionW8.selecteven()
		CoeficientsW8 = DeompositionW8.selectodd().Mt_lut( " X 128 - abs "+string(thresh/8)+" <= 128 x ? ", u=3, v=3)


		## Recomposition

	EvenH8 = iwt(EvenW8, CoeficientsW8).turnleft
	EvenW7 = iwt(EvenH8, CoeficientsH8).Turnright

	EvenH7 = iwt(EvenW7, CoeficientsW7).turnleft
	EvenW6 = iwt(EvenH7, CoeficientsH7).Turnright

	EvenH6 = iwt(EvenW6, CoeficientsW6).turnleft
	EvenW5 = iwt(EvenH6, CoeficientsH6).Turnright

	EvenH5 = iwt(EvenW5, CoeficientsW5).turnleft
	EvenW4 = iwt(EvenH5, CoeficientsH5).Turnright

	EvenH4 = iwt(EvenW4, CoeficientsW4).turnleft
	EvenW3 = iwt(EvenH4, CoeficientsH4).Turnright

	EvenH3 = iwt(EvenW3, CoeficientsW3).turnleft
	EvenW2 = iwt(EvenH3, CoeficientsH3).Turnright

	EvenH2 = iwt(EvenW2, CoeficientsW2).turnleft
	EvenW1 = iwt(EvenH2, CoeficientsH2).Turnright

	EvenH1 = iwt(EvenW1, CoeficientsW1).turnleft
	Complete = iwt(EvenH1, CoeficientsH1)

	complete.crop(1024 - W, 1024 - H, 0, 0)
}
*.mp4 guy is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:02.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.