Пример #1
0
		public static Matrix GetWaveletTransformedMatrix(double[][] image, WaveletMethod waveletMethod)
		{
			int width = image[0].Length;
			int height = image.Length;

			Matrix dwtMatrix = null;

			Stopwatch stopWatch = Stopwatch.StartNew();
			long startS = stopWatch.ElapsedTicks;

			switch(waveletMethod) {
				case WaveletMethod.Dwt:
					Wavelets.Dwt dwt = new Wavelets.Dwt(8);
					Matrix imageMatrix = new Matrix(image);
					dwtMatrix = dwt.Transform(imageMatrix);
					break;
				case WaveletMethod.Haar:
					Haar.Haar2d(image, height, width);
					dwtMatrix = new Matrix(image);
					break;
				case WaveletMethod.HaarTransformTensor: // This is using the tensor product layout
					dwtMatrix = HaarWaveletTransform(image);
					break;
				case WaveletMethod.HaarWaveletDecompositionTensor: // This is using the tensor product layout
					StandardHaarWaveletDecomposition haar = new StandardHaarWaveletDecomposition();
					haar.DecomposeImageInPlace(image);
					dwtMatrix = new Matrix(image);
					break;
				case WaveletMethod.HaarWaveletDecomposition:
					StandardHaarWaveletDecomposition haarNew = new StandardHaarWaveletDecomposition(false);
					haarNew.DecomposeImageInPlace(image);
					dwtMatrix = new Matrix(image);
					break;
				case WaveletMethod.NonStandardHaarWaveletDecomposition:
					NonStandardHaarWaveletDecomposition haarNonStandard = new NonStandardHaarWaveletDecomposition();
					haarNonStandard.DecomposeImageInPlace(image);
					dwtMatrix = new Matrix(image);
					break;
				case WaveletMethod.JWaveTensor: // This is using the tensor product layout
					WaveletInterface wavelet = null;
					wavelet = new Haar02();
					//wavelet = new Daub02();
					TransformInterface bWave = null;
					bWave = new FastWaveletTransform(wavelet);
					//bWave = new WaveletPacketTransform(wavelet);
					//bWave = new DiscreteWaveletTransform(wavelet);
					Transform t = new Transform(bWave); // perform all steps
					double[][] dwtArray = t.forward(image);
					dwtMatrix = new Matrix(dwtArray);
					break;
				case WaveletMethod.HaarWaveletCompress:
					int lastHeight = 0;
					int lastWidth = 0;
					Compress.WaveletCompress.HaarTransform2D(image, 10000, out lastHeight, out lastWidth);
					dwtMatrix = new Matrix(image);
					break;
				default:
					break;
			}

			long endS = stopWatch.ElapsedTicks;
			Console.WriteLine("WaveletMethod: {0} Time in ticks: {1}", Enum.GetName(typeof(WaveletMethod), waveletMethod), (endS - startS));

			//dwtMatrix.WriteCSV("HaarImageNormalized.csv", ";");
			
			// increase all values
			double[][] haarImageNormalized5k = dwtMatrix.MatrixData.Select(i => i.Select(j => j*5000).ToArray()).ToArray();
			//Matrix haarImageNormalized5kMatrix = new Matrix(haarImageNormalized5k);
			//haarImageNormalized5kMatrix.WriteCSV("HaarImageNormalized5k.csv", ";");
			
			// convert to byte values (0 - 255)
			// duplicate the octave/ matlab method uint8
			double[][] uint8 = new double[haarImageNormalized5k.Length][];
			for (int i = 0; i < haarImageNormalized5k.Length; i++) {
				uint8[i] = new double[haarImageNormalized5k.Length];
				for (int j = 0; j < haarImageNormalized5k[i].Length; j++) {
					double v = haarImageNormalized5k[i][j];
					if (v > 255) {
						uint8[i][j] = 255;
					} else if (v < 0) {
						uint8[i][j] = 0;
					} else {
						uint8[i][j] = (byte) haarImageNormalized5k[i][j];
					}
				}
			}
			
			Matrix uint8Matrix = new Matrix(uint8);
			//uint8Matrix.WriteCSV("Uint8HaarImageNormalized5k.csv", ";");
			return uint8Matrix;
		}
Пример #2
0
		public static void TestJWave() {

			double[][] mat = Get2DTestData();

			WaveletInterface wavelet = null;
			wavelet = new Haar02();
			TransformInterface bWave = null;
			//bWave = new FastWaveletTransform(wavelet);
			//bWave = new WaveletPacketTransform(wavelet);
			bWave = new DiscreteWaveletTransform(wavelet);
			Transform t = new Transform(bWave); // perform all steps
			
			Console.Write("\n\nThe 2D JWave Haar02 Dwt method: ");
			Console.Write("\n");
			double[][] dwtArray = t.forward(mat);
			
			Matrix dwtMatrix = new Matrix(dwtArray);
			dwtMatrix.Print();
			
			Console.Write("\n\nThe 2D JWave Haar02 Inverse Dwt method: ");
			Console.Write("\n");
			double[][] idwtArray = t.reverse(dwtArray);

			Matrix idwtMatrix = new Matrix(idwtArray);
			idwtMatrix.Print();
		}
Пример #3
0
		} // JWave

		//   * Main method for doing little test runs for different transform types and
		//   * different wavelets without JUnit. Requesting the transform type and the
		//   * type of wavelet to be used else usage is printed.
		//   * 
		//   * @date 23.02.2010 14:26:47
		//   * @author Christian Scheiblich
		//   * @param args
		//   *          [transformType] [waveletType]
		//
		public static void RunTests(string[] args)
		{
			string waveletTypeList = "Haar02, Lege02, Daub02, Lege04, Daub03, Lege06, Coif06, Daub04";

			if(args.Length < 2 || args.Length > 3)
			{
				System.Console.Error.WriteLine("usage: JWave [transformType] {waveletType} {noOfSteps}");
				System.Console.Error.WriteLine("");
				System.Console.Error.WriteLine("transformType: DFT, FWT, WPT, DWT");
				System.Console.Error.WriteLine("waveletType : " + waveletTypeList);
				System.Console.Error.WriteLine("noOfSteps : " + "no of steps forward and reverse; optional");
				return;
			} // if args

			string wType = args[1];
			WaveletInterface wavelet = null;
			if(wType.Equals("haar02", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Haar02();
			else if(wType.Equals("lege02", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Lege02();
			else if(wType.Equals("daub04", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Daub02();
			else if(wType.Equals("lege04", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Lege04();
			else if(wType.Equals("daub06", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Daub03();
			else if(wType.Equals("lege06", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Lege06();
			else if(wType.Equals("coif06", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Coif06();
			else if(wType.Equals("daub08", StringComparison.InvariantCultureIgnoreCase))
				wavelet = new Daub04();
			else
			{
				System.Console.Error.WriteLine("usage: JWave [transformType] {waveletType}");
				System.Console.Error.WriteLine("");
				System.Console.Error.WriteLine("available wavelets are " + waveletTypeList);
				return;
			} // if wType

			string tType = args[0];
			TransformInterface bWave = null;
			if(tType.Equals("dft", StringComparison.InvariantCultureIgnoreCase))
				bWave = new DiscreteFourierTransform();
			else if(tType.Equals("fwt", StringComparison.InvariantCultureIgnoreCase))
				bWave = new FastWaveletTransform(wavelet);
			else if(tType.Equals("wpt", StringComparison.InvariantCultureIgnoreCase))
				bWave = new WaveletPacketTransform(wavelet);
			else if(tType.Equals("dwt", StringComparison.InvariantCultureIgnoreCase))
				bWave = new DiscreteWaveletTransform(wavelet);
			else
			{
				System.Console.Error.WriteLine("usage: JWave [transformType] {waveletType}");
				System.Console.Error.WriteLine("");
				System.Console.Error.WriteLine("available transforms are DFT, FWT, WPT, DFT");
				return;
			} // if tType

			// instance of transform
			Transform t;

			if(args.Length > 2)
			{
				string argNoOfSteps = args[2];
				int noOfSteps = Convert.ToInt32(argNoOfSteps);

				t = new Transform(bWave, noOfSteps); // perform less steps than possible
			}
			else
			{
				t = new Transform(bWave); // perform all steps
			}

			double[] arrTime = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };

			Console.WriteLine("");
			Console.WriteLine("time domain:");
			for(int p = 0; p < arrTime.Length; p++)
				Console.Write("{0,9:F6}", arrTime[p]);
			Console.WriteLine("");

			double[] arrFreqOrHilb = t.forward(arrTime); // 1-D forward transform

			if(bWave is DiscreteFourierTransform)
				Console.WriteLine("frequency domain:");
			else
				Console.WriteLine("Hilbert domain:");
			for(int p = 0; p < arrTime.Length; p++)
				Console.Write("{0,9:F6}", arrFreqOrHilb[p]);
			Console.WriteLine("");

			double[] arrReco = t.reverse(arrFreqOrHilb); // 1-D reverse transform

			Console.WriteLine("reconstruction:");
			for(int p = 0; p < arrTime.Length; p++)
				Console.Write("{0,9:F6}", arrReco[p]);
			Console.WriteLine("");

		} // main