public void ConvertTest3() { double[] pixels = { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, }; var conv1 = new ArrayToBitmapSource(width: 4, height: 4); BitmapSource image; conv1.Convert(pixels, out image); var conv = new BitmapSourceToArray(); double[] array; conv.Convert(image, out array); var conv2 = new ArrayToImage(width: 4, height: 4); Bitmap image2; conv2.Convert(pixels, out image2); Assert.AreEqual(0, array.Min()); Assert.AreEqual(1, array.Max()); Assert.AreEqual(16, array.Length); var expected = image2.ToVector(0); Assert.AreEqual(array, expected); }
public void ConvertTest2() { // Create an array representation // of a 4x4 image with a inner 2x2 // square drawn in the middle double[] pixels = { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, }; // Create the converter to create a Bitmap from the array var conv = new ArrayToBitmapSource(width: 4, height: 4); // Declare a bitmap source and store the pixels on it BitmapSource image; conv.Convert(pixels, out image); double[,] expected = { { 0, 0, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 0, 0, 0 }, }; double[,] result = image.ToMatrix(0); Assert.AreEqual(expected, result); Assert.AreEqual(PixelFormats.Gray32Float, image.Format); }
public void ConvertTest3() { // Create an array representation // of a 4x4 image with a inner 2x2 // square drawn in the middle byte[] pixels = { 0, 0, 0, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 0, 0, 0, }; // Create the converter to create a Bitmap from the array var conv = new ArrayToBitmapSource(width: 4, height: 4); // Declare an image and store the pixels on it BitmapSource image; conv.Convert(pixels, out image); var conv2 = new ArrayToImage(width: 4, height: 4); Bitmap expected; conv2.Convert(pixels, out expected); Assert.AreEqual(expected.ToMatrix(0), image.ToMatrix(0)); }
public void ConvertTest3() { double[] pixels = { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, }; var conv1 = new ArrayToBitmapSource(width: 4, height: 4); BitmapSource image; conv1.Convert(pixels, out image); image = new ResizeNearestNeighbor(16, 16).Apply(image); // Obtain an image // Bitmap image = ... // Show on screen //ImageBox.Show(image, PictureBoxSizeMode.Zoom); // Create the converter to convert the image to a // matrix containing only values between 0 and 1 var conv = new BitmapSourceToMatrix(); // Convert the image and store it in the matrix double[,] matrix; conv.Convert(image, out matrix); /* * // Show the matrix on screen as an image * ImageBox.Show(matrix, PictureBoxSizeMode.Zoom); * * * // Show the matrix on screen as a .NET multidimensional array * MessageBox.Show(matrix.ToString(CSharpMatrixFormatProvider.InvariantCulture)); * * // Show the matrix on screen as a table * DataGridBox.Show(matrix, nonBlocking: true) * .SetAutoSizeColumns(DataGridViewAutoSizeColumnsMode.Fill) * .SetAutoSizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders) * .SetDefaultFontSize(5) * .WaitForClose(); */ Assert.AreEqual(0, matrix.Min()); Assert.AreEqual(1, matrix.Max()); Assert.AreEqual(16 * 16, matrix.Length); }
public void ConvertTest1() { var target = new ArrayToBitmapSource(16, 16); double[] pixels = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, // 2 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 11 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 12 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, // 13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 14 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 15 }; BitmapSource imageActual; target.Convert(pixels, out imageActual); double[] actual; var c = new BitmapSourceToArray(); c.Convert(imageActual, out actual); double[] expected; BitmapSource imageExpected = TestTools.GetImage("image1.bmp"); Bitmap bitmapImageExpected = imageExpected.ToBitmap(); new Invert().ApplyInPlace(bitmapImageExpected); new Threshold().ApplyInPlace(bitmapImageExpected); BitmapSource imageExpected2 = bitmapImageExpected.ToBitmapSource(); c.Convert(imageExpected2, out expected); for (int i = 0; i < pixels.Length; i++) { Assert.AreEqual(actual[i], expected[i]); } }
public void ConvertTest4() { // Create an array representation // of a 4x4 image with a inner 2x2 // square drawn in the middle System.Windows.Media.Color[] pixels = { Colors.Red, Colors.Lime, Colors.Blue, Colors.Black, Colors.Black, Colors.Transparent, Colors.Red, Colors.Black, Colors.Black, Colors.Lime, Colors.Blue, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, }; // Create the converter to create a Bitmap from the array var conv = new ArrayToBitmapSource(width: 4, height: 4); // Declare an image and store the pixels on it BitmapSource image; conv.Convert(pixels, out image); System.Drawing.Color[] pixels2 = { Color.Red, Color.Lime, Color.Blue, Color.Black, Color.Black, Color.Transparent, Color.Red, Color.Black, Color.Black, Color.Lime, Color.Blue, Color.Black, Color.Black, Color.Black, Color.Black, Color.Black, }; ArrayToImage conv2 = new ArrayToImage(width: 4, height: 4); Bitmap image2; conv2.Convert(pixels2, out image2); var actual = image.ToMatrix(); var expected = image2.ToMatrix(); Assert.AreEqual(expected, actual); }