(* ::Package:: *) (* : Title : MyDiscreteWavelets.m-- a package template*) (* : Context : DiscreteWavelets`MyDiscreteWavelets`*) (* : Author : Patrick J.Van Fleet*) (* : Summary : This package contains routines student routines for computing one and two dimensional wavelet transformations. Also contained in the package are other routines used in applications involving discrete wavelet transformations.*) (* : Copyright : \[Copyright] 2008 by Patrick J.Van Fleet*) (* : Package Version : 1.0*) (* : Mathematica Version : 6.0*) (* : History :*) (* : Keywords : wavelets, filters, cumulative energy, peak signal to noise ratio, entropy, Huffman codes, color spaces*) (* : Sources : Patrick J.Van Fleet, Discrete Wavelet Transformations : An Elementary Approach With Applications.*) (* : Warnings : This package only works with Mathematica version 6.0 or later!!*) (* : Limitations : < special cases not handled, known problems >*) (* : Discussion : < description of algorithm, information for experts >*) (* : Requirements : None *) (* : Examples : < sample input that demonstrates the features of this package >*) BeginPackage["DiscreteWavelets`MyDiscreteWavelets`"]; (*Functions usage messages*) MyCE::usage = "MyCE returns the cumulative energy vector of the input vector v or \ matrix A." MyComp::usage = "MyComp takes a vector v or a matrix A and an integer index k and \ first computes the kth largest element (in absolute value) in v. If we call this value q, Comp then sets to 0 all values in v smaller (in \ absolute value) than q and returns this modified vector. If k is larger than \ the number of elements in v or A, then k is reset to the number of elements \ in v or A. If k is 0 or negative, Comp converts all elements to 0." MynCE::usage = "MynCE takes a vector built from CE and a percentage p and returns \ an index k so that p% of the energy of v is stored in the first k components \ of v." MyEntropy::usage = "MyEntropy takes a vector v or a matrix A and returns the \ entropy." MyMSE::usage="MyMSE takes as input two matrices and returns their mean squared \ error." MyPSNR::usage = "MyPSNR takes as input two matrices and returns the Peak Signal \ to Noise Ratio between the two matrices. PSNR calls the MSE function." MyRGBToYCbCr::usage="MyRGBToYCbCr converts from RGB to YCbCr. The input can be a \ single rgb point {r,g,b}, a list of such points, or a list of three matrices \ (presumably red, green, and blue). If DisplayMode is set to True, then the \ conversion is stretched to prevent roundoff error. This is useful for \ displaying the three channels." MyYCbCrToRGB::usage="MyYCbCrToRGB converts from YCbCr to RGB. The input can be a \ single rgb point {y,u,v}, a list of such points, or a list of three matrices \ (presumably y, u, and v values). If DisplayMode is set to True, then the \ conversion is stretched to prevent roundoff error. This is useful for \ displaying the three channels." MyMakeHuffmanCodes::usage = "MyMakeHuffmanCodes takes a string of characters, a \ vector of integers, or a matrix of integers, and returns the codes for the \ elements, the original bitstream length, and the bitstream length of the \ Huffman codes." MyDaub::usage = "MyDaub takes an even positive integer n as an argument and \ returns the Daubechies filter of length n." MyCoif::usage="MyCoif takes a positive integer K as an argument and returns the \ Coiflet filter of length 6*K. Currently this routines only works for K=1, 2, \ 3." MySplineFilters::usage="MySplineFilters takes two even integers M and Mt and \ returns the associated biorthogonal spline filter pair. If only one integer \ is given, SplineFilters returns the Haar filter pair." MyCDF97::usage="MyCDF97 returns the Cohen/Daubechies/Feauveau 9/7 filter pair \ (see Section 10.3)." MyHWT1D1::usage="MyHWT1D1 takes a vector v of even length and returns its Haar \ wavelet transform." MyIHWT1D1::usage="MyIHWT1D1 takes a vector v of even length and returns its \ inverse Haar wavelet transform." MyHWT1D::usage="MyHWT1D takes a vector v of length 2^p and an integer i between 0 \ and p inclusive and returns i iterations of the Haar Wavelets Transform." MyIHWT1D::usage="MyIHWT1D takes a vector v of length 2^p and an integer i between \ 0 and p inclusive and returns i iterations of the Inverse Haar Wavelet \ Transform." MyWT1D1::usage="MyWT1D1 takes an even-length vector v and a filter h and returns \ one iteration of the wavelet transform. If a filter h is not input, WT1D1 \ computes one iteration of the Haar wavelet transform." MyIWTht::usage="MyIWTht is an auxiliary routine used by IWT1D1 to compute half of \ the inverse wavelet transform on input vector v." MyIWT1D1::usage="MyIWT1D1 takes an even-length vector v and a filter h and \ returns one iteration of the inverse wavelet transform. If a filter h is not \ input, IWT1D1 computes one iteration of the inverse Haar wavelet transform." MyWT1D::usage="MyWT1D takes an even-length vector v and a filter h and performs \ an iterated wavelet transform. The number of iterations is set as a \ directive. If no directive is given, the routine computes one iteration. If \ no filter is given, the routine computes the iterated Haar wavelet \ transform." MyIWT1D::usage="MyIWT1D takes an even-length vector v and a filter h and performs \ an iterated inverse wavelet transform. The number of iterations is set as a \ directive. If no directive is given, the routine computes one iteration. If \ no filter is given, the routine computes the iterated inverse Haar wavelet \ transform." MyBWT1D1::usage="MyBWT1D1 takes an even-length vector v and a biorthogonal filter \ pair {h,hw} and returns one iteration of the biorthogonal wavelet transform." MyIBWTht::usage="MyIBWTht is an auxiliary routine used by IBWT1D1 to compute half \ of the inverse wavelet transform on input vector v." MyIBWT1D1::usage="MyIBWT1D1 takes an even-length vector v and a biorthogonal \ filter pair {h,hw} and returns one iteration of the inverse biorthogonal \ wavelet transform." MyBWT1D::usage="MyBWT1D takes an even-length vector v and a filter pair h, hw and \ performs an iterated biorthogonal wavelet transform. The number of \ iterations is set as a directive. If no directive is given, the routine \ computes one iteration. If no filter is given, the routine computes the \ iterated Haar wavelet transform." MyIBWT1D::usage="MyIBWT1D takes an even-length vector v and a filter pair h, hw \ and performs an iterated inverse biorthogonal wavelet transform. The number \ of iterations is set as a directive. If no directive is given, the routine \ computes one iteration. If no filter is given, the routine computes the \ iterated inverse Haar wavelet transform." MyLWT1D1::usage="MyLWT1D1 takes an even-length vector v and employs lifting to \ return one iteration of the biorthogonal wavelet transform using the LeGall \ filter pair." MyILWT1D1::usage="MyILWT1D1 takes an even-length vector v and employs lifting to \ return one iteration of the inverse biorthogonal wavelet transform using the \ LeGall filter pair." MyLWT1D::usage="MyLWT1D takes an even-length vector v and employs lifting to \ return an iterated biorthogonal wavelet transform using the LeGall filter \ pair. The number of iterations is set as a directive. If no directive is \ given, the routine computes one iteration." MyILWT1D::usage="MyILWT1D takes an even-length vector v and employs lifting to \ return an iterated inverse biorthogonal wavelet transform using the LeGall \ filter pair. The number of iterations is set as a directive. If no \ directive is given, the routine computes one iteration." MyLeftHWT::usage="MyLeftHWT multiplies input matrix A on the left by the \ transpose of the Haar transform matrix." MyHWT2D1::usage="MyHWT2D1 returns one iteration of the two-dimensional Haar \ wavelet transform." MyLeftIHWT::usage="MyLeftIHWT multiplies input matrix A on the left by the \ inverse Haar transform matrix." MyIHWT2D1::usage="MyIHWT2D1 returns one iteration of the two-dimensional inverse \ Haar wavelet transform." MyHWT2D::usage="MyHWT2D returns the iterated two-dimensional Haar wavelet \ transform." MyIHWT2D::usage="MyIHWT2D returns the iterated inverse two-dimensional Haar \ wavelet transform." MyLeftWT::usage="MyLeftWT multiplies input matrix A on the left by the transpose \ of the wavelet transform matrix built from input filter h." MyWT2D1::usage="MyWT2D1 returns one iteration of the two-dimensional wavelet \ transform built from input filter h." MyLeftIWT::usage="MyLeftIWT multiplies input matrix A on the left by the inverse \ wavelet transform matrix built from input filter h." MyIWT2D1::usage="MyIWT2D1 returns one iterations of the two-dimensional inverse \ wavelet transform built from input filter h." MyWT2D::usage="MyWT2D returns the iterated two-dimensional wavelet transform \ built from input filter h." MyIWT2D::usage="MyIWT2D returns the iterated two-dimensional inverse wavelet \ transform built from input filter h." MyBWT2D1::usage="MyBWT2D1 returns one iteration of the two-dimensional \ biorthogonal wavelet transform built from input filter pair {h, hw}." MyIBWT2D1::usage="MyIBWT2D1 returns one iteration of the two-dimensional inverse \ biorthogonal wavelet transform built from input filter pair {h, hw}." MyBWT2D::usage="MyBWT2D returns the iterated two-dimensional biorthogonal wavelet \ transform built from input filter pair {h,hw}." MyIBWT2D::usage="MyIBWT2D returns the iterated two-dimensional inverse \ biorthogonal wavelet transform built from input filter pair {h,hw}." MyLWT2D1::usage="MyLWT2D1 returns one iteration of the two-dimensional \ biorthogonal wavelet transform via lifting using the LeGall filter pair." MyILWT2D1::usage="MyILWT2D1 returns one iteration of the two-dimensional inverse \ biorthogonal wavelet transform via lifting using the LeGall filter pair." MyLWT2D::usage="MyLWT2D returns the iterated two-dimensional biorthogonal wavelet \ transform via lifting built from the LeGall filter pair." MyILWT2D::usage="MyILWT2D returns the iterated two-dimensional inverse \ biorthogonal wavelet transform via lifting built from the LeGall filter \ pair." MyGammaCorrection::usage="MyGammaCorrection takes a grayscale image matrix a and \ a value r and uses r to perfom gamma correction on a." MyMakeHistogramEQ::usage="MyMakeHistogramEQ takes a grayscale image matrix a and \ returns a histogram that shows the distribution of intensities in the image." MyHistogramEQ::usage="MyHistogramEQ takes a grayscale image matrix a and returns \ the histogram equalized image." MyDonohoSure::usage="MyDonohoSure takes as input a vector v and returns the SUREShrink tolerance lambda." MyWaveletShrinkage::usage="MyWaveletShrinkage takes a vector or matrix, an orthogonal filter, a tolerance (or list of tolerances), and a number of iterations for the wavelet transform and returns a denoised version of the input vector or matrix. The module uses Algorithm 9.1 from Section 9.1 of the book." (* Options *) Options[MyRGBToYCbCr] = Options[MyYCbCrToRGB] = {MyDisplayMode->False}; Options[MyDaub] = Options[MyCoif] = {Precision -> $MachinePrecision}; Options[MySplineFilters]={MyPrintInfo->False}; Options[MyHWT1D] = Options[MyIHWT1D] = Options[MyWT1D] = Options[MyIWT1D] = {MyNumIterations->1}; Options[MyBWT1D1] = Options[MyIBWT1D1] = {MyBoundary->None}; Options[MyBWT1D] = Options[MyIBWT1D] = {MyNumIterations->1,MyBoundary->None}; Options[MyLWT1D1] = Options[MyILWT1D1] = {MyIntegerMap->False}; Options[MyLWT1D] = Options[MyILWT1D] = {MyNumIterations->1,MyIntegerMap->False}; Options[MyHWT2D] = Options[MyIHWT2D] = Options[MyWT2D] = Options[MyIWT2D] = {MyNumIterations->1}; Options[MyBWT2D1] = Options[MyIBWT2D1] = {MyBoundary->None}; Options[MyBWT2D] = Options[MyIBWT2D] = {MyNumIterations->1,MyBoundary->None}; Options[MyLWT2D1] = Options[MyILWT2D1] = {MyIntegerMap->False}; Options[MyLWT2D] = Options[MyILWT2D] = {MyNumIterations->1,MyIntegerMap->False}; Options[MyWaveletShrinkage]={MyNumIterations->1}; Begin["`Private`"] Off[General::spell]; Off[General::spell1]; MyCE[v_] := Module[{y},y=1;Return[y]]; MyComp[v_,k_]:= Module[{y},y=1;Return[y]]; MynCE[v_, p_]:= Module[{y},y=1;Return[y]]; MyEntropy[v_]:= Module[{y},y=1;Return[y]]; MyMSE[a_,b_]:= Module[{y},y=1;Return[y]]; MyPSNR[a_, b_] := Module[{y},y=1;Return[y]]; MyRGBToYCbCr[c_,opts___]:= Module[{y},y=1;Return[y]]; MyYCbCrToRGB[c_,opts___]:= Module[{y},y=1;Return[y]]; MyMakeHuffmanCodes[v_]:= Module[{y},y=1;Return[y]]; MyDaub[n_Integer, opts___] := Module[{y},y=1;Return[y]]; MyCoif[K_,opts___]:= Module[{y},y=1;Return[y]]; MySplineFilters[M_,Mw_,opts___]:= Module[{y},y=1;Return[y]]; MyCDF97[___]:= Module[{y},y=1;Return[y]]; MyHWT1D1[v_]:= Module[{y},y=1;Return[y]]; MyIHWT1D1[v_]:= Module[{y},y=1;Return[y]]; MyHWT1D[v_, opts___]:= Module[{y},y=1;Return[y]]; MyWT1D1[v_,h_]:= Module[{y},y=1;Return[y]]; MyIWTht[v_,h_]:= Module[{y},y=1;Return[y]]; MyIWT1D1[v_,h_]:= Module[{y},y=1;Return[y]]; MyWT1D[v_,h_,opts___]:= Module[{y},y=1;Return[y]]; MyIWT1D[v_,h_,opts___]:= Module[{y},y=1;Return[y]]; MyBWT1D1[v_, {h__, hw___}, opts___]:= Module[{y},y=1;Return[y]]; MyIBWTht[v_,f_,i_]:= Module[{y},y=1;Return[y]]; MyIBWT1D1[v_, {h__,hw___}, opts___]:= Module[{y},y=1;Return[y]]; MyBWT1D[v_, {h__,hw___}, opts___]:= Module[{y},y=1;Return[y]]; MyIBWT1D[v_,{h__,hw___},opts___]:= Module[{y},y=1;Return[y]]; MyLWT1D1[v_,opts___]:= Module[{y},y=1;Return[y]]; MyILWT1D1[v_,opts___]:= Module[{y},y=1;Return[y]]; MyLWT1D[v_, opts___]:= Module[{y},y=1;Return[y]]; MyILWT1D[v_,opts___]:= Module[{y},y=1;Return[y]]; MyLeftHWT[a_]:=Module[{y},y=1;Return[y]]; MyHWT2D1[a_]:= Module[{y},y=1;Return[y]]; MyLeftIHWT[a_]:=Module[{y},y=1;Return[y]]; MyIHWT2D1[a_]:= Module[{y},y=1;Return[y]]; MyHWT2D[a_,opts___]:= Module[{y},y=1;Return[y]]; MyIHWT2D[a_,opts___]:= Module[{y},y=1;Return[y]]; MyLeftWT[a_,h_]:=Module[{y},y=1;Return[y]]; MyWT2D1[a_,h___]:= Module[{y},y=1;Return[y]]; MyLeftIWT[a_,h_]:=Module[{y},y=1;Return[y]]; MyIWT2D1[a_,h___]:= Module[{y},y=1;Return[y]]; MyWT2D[a_,h__,opts___]:= Module[{y},y=1;Return[y]]; MyIWT2D[a_,h__,opts___]:= Module[{y},y=1;Return[y]]; MyBWT2D1[a_,{h__,hw___},opts___]:= Module[{y},y=1;Return[y]]; MyIBWT2D1[a_,{h__,hw___},opts___]:= Module[{y},y=1;Return[y]]; MyBWT2D[a_,{h__,hw___},opts___]:= Module[{y},y=1;Return[y]]; MyIBWT2D[a_,{h__,hw___},opts___]:= Module[{y},y=1;Return[y]]; MyLWT2D1[a_,opts___]:= Module[{y},y=1;Return[y]]; MyILWT2D1[a_,opts___]:= Module[{y},y=1;Return[y]]; MyLWT2D[a_,opts___]:= Module[{y},y=1;Return[y]]; MyILWT2D[a_,opts___]:= Module[{y},y=1;Return[y]]; MyGammaCorrection[a_,r_:1]:= Module[{y},y=1;Return[y]]; MyMakeHistogramEQ[a_]:= Module[{y},y=1;Return[y]]; MyHistogramEQ[a_]:= Module[{y},y=1;Return[y]]; MyDonohoSure[v_]:= Module[{y},y=1;Return[y]]; MyWaveletShrinkage[a_,h_,lambda_,opts___]:= Module[{y},y=1;Return[y]]; End[] EndPackage[];