public double[] ConvertImageToDouble(Bitmap imageBitmap)
        {
            Grayscale     gs            = new Grayscale(0, 0, 0);
            ImageToMatrix imageToMatrix = new ImageToMatrix();

            imageBitmap = gs.Apply(imageBitmap);
            imageToMatrix.Convert(imageBitmap, out byte[][] imageBytes);

            foreach (byte[] t in imageBytes)
            {
                for (var j = 0; j < t.Length; j++)
                {
                    if (t[j] > 190)
                    {
                        t[j] = 1;
                    }
                    else
                    {
                        t[j] = 0;
                    }
                }
            }

            return(imageBytes.Flatten().ToDouble());
        }
Example #2
0
        public static bool RotateTest32bpp(IFilter filter, Bitmap input, Bitmap output)
        {
            var itm = new ImageToMatrix();

            // Test directly
            Color[,] actual;
            itm.Convert(filter.Apply(input), out actual);

            Color[,] expected;
            itm.Convert(output, out expected);

            if (!actual.IsEqual(expected))
            {
                return(false);
            }

            // Rotate and re-test
            var rotate = new RotateNearestNeighbor(90, false);

            input  = rotate.Apply(input);
            output = rotate.Apply(output);

            itm.Convert(filter.Apply(input), out actual);
            itm.Convert(output, out expected);

            return(actual.IsEqual(expected));
        }
        public double[] ConvertImageToDouble(Bitmap imageBitmap)
        {
            ImageToMatrix imageToMatrix = new ImageToMatrix();

            imageToMatrix.Convert(imageBitmap, out byte[][] imageBytes);
            imageToMatrix.Convert(imageBitmap, out Color[][] imageColors);

            Color characterColor = imageColors.SelectMany(c => c).GroupBy(c => c.Name).OrderByDescending(g => g.Count()).ElementAt(1).ElementAt(0);

            for (var i = 0; i < imageBytes.Length; i++)
            {
                for (var j = 0; j < imageBytes[i].Length; j++)
                {
                    if (imageColors[i][j].Name == characterColor.Name)
                    {
                        imageBytes[i][j] = 1;
                    }
                    else
                    {
                        imageBytes[i][j] = 0;
                    }
                }
            }

            return(imageBytes.Flatten().ToDouble());
        }
        public void ImageToMatrixConstructorTest1()
        {
            ImageToMatrix target = new ImageToMatrix();

            Assert.AreEqual(0, target.Min);
            Assert.AreEqual(1, target.Max);
            Assert.AreEqual(0, target.Channel);
        }
Example #5
0
        public void ImageToMatrixConstructorTest1()
        {
            ImageToMatrix target = new ImageToMatrix();

            Assert.AreEqual(0, target.Min);
            Assert.AreEqual(1, target.Max);
            Assert.AreEqual(0, target.Channel);
        }
Example #6
0
        public static float[,] FromBitmap(Bitmap image)
        {
            ImageToMatrix i2m = new ImageToMatrix();

            float[,] texture;
            i2m.Convert(image, out texture);
            return(texture);
        }
Example #7
0
        public byte[,] Dat2DownMat(string path, int length, double scale)
        {
            //try
            //{
            //	Matrix2Bitmap = new MatrixToImage();
            //	Bitmap2matrix = new ImageToMatrix();
            //
            //	Stream loadstream = new FileStream(path, FileMode.Open);
            //	byte[] oneshotVector = new byte[length];
            //	loadstream.Read( oneshotVector , 0 , oneshotVector.Length );
            //	loadstream.Dispose();
            //
            //	byte[,] temp = Vec2Mat(oneshotVector, ImgInfo.W, ImgInfo.H); // ok
            //	oneshotVector = null;
            //
            //	Bitmap tempbit = new Bitmap(ImgInfo.W, ImgInfo.H, PixelFormat.Format4bppIndexed);
            //	Matrix2Bitmap.Convert( temp , out tempbit );
            //	temp = null;
            //	Bitmap tempdown = new Bitmap(tempbit, new Size((int)(ImgInfo.W / scale), (int)(ImgInfo.H / scale)));
            //	tempbit = null;
            //	byte[,] arrdown = new byte[(int)(tempdown.Width / scale), (int)(tempdown.Height / scale)];
            //	Bitmap2matrix.Convert( tempdown , out arrdown );
            //	tempdown = null;
            //	//arrdown = Matrix.Transpose(arrdown);
            //	return arrdown;
            //}

            try
            {
                Matrix2Bitmap = new MatrixToImage();
                Bitmap2matrix = new ImageToMatrix();

                Stream loadstream    = new FileStream(path, FileMode.Open);
                byte[] oneshotVector = new byte[length];
                loadstream.Read(oneshotVector, 0, oneshotVector.Length);
                loadstream.Dispose();

                byte[,] temp  = Accord.Math.Matrix.Transpose(Vec2Mat(oneshotVector, ImgInfo.W, ImgInfo.H));                 // ok
                oneshotVector = null;

                //Bitmap tempbit = new Bitmap(ImgInfo.W, ImgInfo.H, PixelFormat.Format4bppIndexed);
                //Matrix2Bitmap.Convert(temp, out tempbit);
                //temp = null;
                //Bitmap tempdown = new Bitmap(tempbit, new Size((int)(ImgInfo.W / scale), (int)(ImgInfo.H / scale)));
                //tempbit = null;
                //byte[,] arrdown = new byte[(int)(tempdown.Width / scale), (int)(tempdown.Height / scale)];
                //Bitmap2matrix.Convert(tempdown, out arrdown);
                //tempdown = null;
                //arrdown = Matrix.Transpose(arrdown);
                return(temp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(new byte[0, 0]);
            }
        }
        public void ImageToMatrixConstructorTest()
        {
            double min = -10;
            double max = +10;
            ImageToMatrix target = new ImageToMatrix(min, max);

            Assert.AreEqual(min, target.Min);
            Assert.AreEqual(max, target.Max);
            Assert.AreEqual(0, target.Channel);
        }
Example #9
0
        public void ImageToMatrixConstructorTest()
        {
            double        min    = -10;
            double        max    = +10;
            ImageToMatrix target = new ImageToMatrix(min, max);

            Assert.AreEqual(min, target.Min);
            Assert.AreEqual(max, target.Max);
            Assert.AreEqual(0, target.Channel);
        }
Example #10
0
        /// <summary>
        /// Metoda konwertująca obraz do Bitmap, a następnie na macierz
        /// </summary>
        /// <param name="localPath">Ścieżka do pliku</param>
        /// <returns>Macierz pixeli</returns>
        public double[,] GetPixelArray(string localPath)
        {
            double[,] result;
            Bitmap image = new Bitmap(localPath);

            ImageToMatrix conventer = new ImageToMatrix(min: 0, max: 1);

            conventer.Convert(image, out result);

            return(result);
        }
Example #11
0
        public void ConvertTest3()
        {
            double[] pixels =
            {
                0, 0, 0, 0,
                0, 1, 1, 0,
                0, 1, 1, 0,
                0, 0, 0, 0,
            };


            ArrayToImage conv1 = new ArrayToImage(width: 4, height: 4);
            Bitmap       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
            ImageToMatrix conv = new ImageToMatrix(min: 0, max: 1);

            // 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);
        }
Example #12
0
        public void ConvertTest1()
        {
            MatrixToImage target = new MatrixToImage();

            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 },  // 11new Bitmap(Properties
                { 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
            };

            Bitmap imageActual;

            target.Convert(pixels, out imageActual);


            double[,] actual;
            ImageToMatrix c = new ImageToMatrix();

            c.Convert(imageActual, out actual);

            double[,] expected;
            Bitmap imageExpected = Accord.Imaging.Image.Clone(Resources.image1);

            new Threshold().ApplyInPlace(imageExpected);
            new Invert().ApplyInPlace(imageExpected);
            c.Convert(imageExpected, out expected);


            for (int i = 0; i < pixels.GetLength(0); i++)
            {
                for (int j = 0; j < pixels.GetLength(1); j++)
                {
                    Assert.AreEqual(actual[i, j], expected[i, j]);
                }
            }
        }
Example #13
0
        private static void test(string actual, string expected)
        {
            string basePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources", "PNM");

            string fileName    = Path.Combine(basePath, actual);
            Bitmap actualImage = ImageDecoder.DecodeFromFile(fileName);

            string expectedFileName = Path.Combine(basePath, expected);
            Bitmap expectedImage    = (Bitmap)Bitmap.FromFile(expectedFileName);

            var i2m = new ImageToMatrix();

            byte[,] actualMatrix;
            i2m.Convert(actualImage, out actualMatrix);

            byte[,] expectedMatrix;
            i2m.Convert(expectedImage, out expectedMatrix);

            Assert.IsTrue(expectedMatrix.IsEqual(actualMatrix, (byte)1));
        }
Example #14
0
        public void ConvertTest2()
        {
            // Load a test image
            Bitmap sourceImage = Accord.Imaging.Image.Clone(Properties.Resources.image1);

            // Make sure values are binary
            new Threshold().ApplyInPlace(sourceImage);

            // Create the converters
            ImageToMatrix imageToMatrix = new ImageToMatrix()
            {
                Min = 0, Max = 255
            };
            MatrixToImage matrixToImage = new MatrixToImage()
            {
                Min = 0, Max = 255
            };

            // Convert to matrix
            double[,] matrix; // initialization is not needed
            imageToMatrix.Convert(sourceImage, out matrix);

            // Revert to image
            Bitmap resultImage; // initialization is not needed

            matrixToImage.Convert(matrix, out resultImage);

            // Show both images, which should be equal
            // ImageBox.Show(sourceImage, PictureBoxSizeMode.Zoom);
            // ImageBox.Show(resultImage, PictureBoxSizeMode.Zoom);

            UnmanagedImage img1 = UnmanagedImage.FromManagedImage(sourceImage);
            UnmanagedImage img2 = UnmanagedImage.FromManagedImage(resultImage);

            List <IntPoint> p1 = img1.CollectActivePixels();
            List <IntPoint> p2 = img2.CollectActivePixels();

            bool equals = new HashSet <IntPoint>(p1).SetEquals(p2);

            Assert.IsTrue(equals);
        }
Example #15
0
        public byte[,] Dat2Mat(string path)
        {
            try
            {
                Matrix2Bitmap = new MatrixToImage();
                Bitmap2matrix = new ImageToMatrix();

                Stream loadstream    = new FileStream(path, FileMode.Open);
                byte[] oneshotVector = new byte[ImgInfo.WH];
                loadstream.Read(oneshotVector, 0, oneshotVector.Length);
                loadstream.Dispose();
                byte[,] temp  = Vec2Mat(oneshotVector, ImgInfo.W, ImgInfo.H); // ok
                oneshotVector = null;
                return(temp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(new byte[0, 0]);
            }
        }
Example #16
0
        public void ConvertTest()
        {
            ImageToMatrix target = new ImageToMatrix(min: 0, max: 255);
            Bitmap        image  = Accord.Imaging.Image.Clone(Properties.Resources.image1);

            new Invert().ApplyInPlace(image);
            new Threshold().ApplyInPlace(image);

            double[,] output;
            double[,] outputExpected =
            {
                { 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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
            };


            target.Convert(image, out output);

            for (int i = 0; i < outputExpected.GetLength(0); i++)
            {
                for (int j = 0; j < outputExpected.GetLength(1); j++)
                {
                    Assert.AreEqual(outputExpected[i, j], output[i, j]);
                }
            }
        }
Example #17
0
        private void ReadImageToEntity(string filePath)
        {
            Bitmap image = new Bitmap(filePath);

            ImageToMatrix conv = new ImageToMatrix();

            double[,] res;
            conv.Convert(image, out res);

            for (var i = 0; i < image.Height; i++)
            {
                interferogram.Add(new List <Complex>());

                for (var j = 0; j < image.Width; j++)
                {
                    var k = (i + 1) * j;
                    interferogram[i].Add(new Complex {
                        Real = res[i, j]
                    });
                }
            }
        }
Example #18
0
        public static float[,,,,] PrepareImages(List <DicomImage> dicomList)
        {
            dicomList = GetDistribution(dicomList);

            List <double[, ]> res = new List <double[, ]>();

            foreach (DicomImage dicomImage in dicomList)
            {
                Bitmap bmp = dicomImage.RenderImage().AsSharedBitmap();
                bmp = ResizeBitmap(bmp, 256, 256);
                bmp.RotateFlip(RotateFlipType.Rotate90FlipX);

                ImageToMatrix conv = new ImageToMatrix(min: 0, max: 1);

                double[,] matrix;
                conv.Convert(bmp, out matrix);

                res.Add(matrix);
            }


            var resArr = res.ToArray();

            float[,,,,] arr = new float[1, 16, 256, 256, 1];
            for (byte i = 0; i < 16; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    for (int k = 0; k < 256; k++)
                    {
                        arr[0, i, j, k, 0] = (float)resArr[i][j, k];
                    }
                }
            }


            return(arr);
        }
        public Bitmap[] ExtractCharacters(Bitmap imageBitmap, ColorsEnum?color = null)
        {
            ImageToMatrix imageToMatrix = new ImageToMatrix();

            imageBitmap = new Bitmap(imageBitmap, new Size(260, 51));

            List <Bitmap> charactersBitmap = new List <Bitmap>();

            foreach (int delimiter in _delimiters)
            {
                Bitmap character = imageBitmap
                                   .Clone(new Rectangle {
                    X = delimiter, Y = 8, Width = 27, Height = 29
                }, imageBitmap.PixelFormat);

                charactersBitmap.Add(character);
            }

            if (color != null)
            {
                List <Bitmap> charactersBitmapColor = new List <Bitmap>();
                foreach (Bitmap character in charactersBitmap)
                {
                    imageToMatrix.Convert(character, out Color[][] imageColors);
                    Color characterColor = imageColors.SelectMany(c => c).GroupBy(c => c.Name).OrderByDescending(g => g.Count()).ElementAt(1).ElementAt(0);

                    ColorsEnum result = ColorDecoder.Decode(characterColor);
                    if (result.Equals(color))
                    {
                        charactersBitmapColor.Add(character);
                    }
                }

                charactersBitmap = charactersBitmapColor;
            }

            return(charactersBitmap.ToArray());
        }
Example #20
0
        public static bool RotateTest32bpp(IFilter filter, Bitmap input, Bitmap output)
        {
            var itm = new ImageToMatrix();

            // Test directly
            Color[,] actual;
            itm.Convert(filter.Apply(input), out actual);

            Color[,] expected;
            itm.Convert(output, out expected);

            if (!actual.IsEqual(expected))
                return false;

            // Rotate and re-test
            var rotate = new RotateNearestNeighbor(90, false);
            input = rotate.Apply(input);
            output = rotate.Apply(output);

            itm.Convert(filter.Apply(input), out actual);
            itm.Convert(output, out expected);

            return actual.IsEqual(expected);
        }
Example #21
0
        public void doc_example()
        {
            string basePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources", "PNM");

            #region doc_load
            string filename = Path.Combine(basePath, "lena.pgm");

            // One way to decode the image explicitly is to use
            Bitmap image1 = ImageDecoder.DecodeFromFile(filename);

            // However, you could also obtain the same effect using
            Bitmap image2 = Accord.Imaging.Image.FromFile(filename);
            #endregion

            var i2m = new ImageToMatrix();

            byte[,] actualMatrix;
            i2m.Convert(image1, out actualMatrix);

            byte[,] expectedMatrix;
            i2m.Convert(image2, out expectedMatrix);

            Assert.IsTrue(expectedMatrix.IsEqual(actualMatrix, (byte)1));
        }
Example #22
0
        public List <List <byte[, ]> > ListDownScaledZoomedMat(List <List <string> > input, ZoomData data)
        {
            /* data에 들어있는 리얼 포지션 좌표 값은 스케일링이 안되있다. */
            /* 1. 각 원본 DAt 파일에 어느 좌표부터 어느 좌표까지 가져와야 하는지 계산 */
            /* 2. 데이터를 가져온다음에 리사이즈 */
            /**/
            /**/
            /**/
            /**/

            //Check Start End File Pos and scale ===
            data.Scale = CalcScale(input, data);
            double scale = data.Scale; // 여기서 스케일이 정해진다. 이것은 실제 데이터 가져온후 이미지 -> 스케일변환 ->

            Console.WriteLine("Scale Value is " + $"  {scale} ");
            /* Class Instance*/
            FormatConvert fcv = new FormatConvert();

            Matrix2Bitmap = new MatrixToImage();
            Bitmap2matrix = new ImageToMatrix();

            int width  = data.Ex - data.Sx;
            int height = data.Ey - data.Sy;
            int WCount = data.endNumX - data.startNumX;
            int HCount = data.endNumY - data.startNumY;


            int strPosX = 0;
            int strPosY = 0;
            int endPosX = 0;
            int endPosY = 0;

            List <List <byte[, ]> > box = new List <List <byte[, ]> >();

            if ((data.endNumX - data.startNumX) == 0 && (data.endNumY - data.startNumY) == 0)
            {
                /*OK*/
                #region
                List <byte[, ]> tempbox = new List <byte[, ]>();
                string          path    = input[data.startNumX][data.startNumY];
                strPosX = data.Sx - data.startNumX * data.Wo;
                strPosY = data.Sy - data.startNumY * data.Ho;
                endPosX = data.Ex - data.endNumX * data.Wo;
                endPosY = data.Ey - data.endNumY * data.Ho;

                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                box.Add(tempbox);
                #endregion
            }
            else if ((data.endNumY - data.startNumY) == 0)
            {
                /*OK*/
                #region
                for (int i = data.startNumX; i <= data.endNumX; i++)
                {
                    string path = input[i][data.startNumY];

                    List <byte[, ]> tempbox = new List <byte[, ]>();
                    if (i == data.startNumX)
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else if (i == data.endNumX)
                    {
                        strPosX = 0;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Ex - data.endNumX * data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else
                    {
                        strPosX = 0;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    box.Add(tempbox);
                }
                #endregion
            }
            else if ((data.endNumX - data.startNumX) == 0)
            {
                /*OK*/
                #region
                List <byte[, ]> tempbox = new List <byte[, ]>();
                for (int j = data.startNumY; j <= data.endNumY; j++)
                {
                    string path = input[data.startNumX][j];
                    if (j == data.startNumY)
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Ex - data.startNumX * data.Wo;
                        endPosY = data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else if (j == data.endNumY)
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = 0;
                        endPosX = data.Ex - data.startNumX * data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = 0;
                        endPosX = data.Ex - data.startNumX * data.Wo;
                        endPosY = data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                }
                box.Add(tempbox);
                #endregion
            }
            else
            {
                for (int i = data.startNumX; i <= data.endNumX; i++)
                {
                    List <byte[, ]> tempbox = new List <byte[, ]>();

                    if (i == data.startNumX)
                    {
                        #region Start X Pos
                        for (int j = data.startNumY; j <= data.endNumY; j++)
                        {
                            string path = input[i][j];
                            if (j == data.startNumY)
                            {
                                /* Pixel Position in One File Matrix*/
                                strPosX = data.Sx - i * data.Wo;
                                strPosY = data.Sy - j * data.Ho;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else if (j == data.endNumY)
                            {
                                strPosX = data.Sx - i * data.Wo;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ey - j * data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else
                            {
                                strPosX = data.Sx - i * data.Wo;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                        }
                        #endregion
                    }
                    else if (i == data.endNumX)
                    {
                        #region End X Pos
                        for (int j = data.startNumY; j <= data.endNumY; j++)
                        {
                            string path = input[i][j];
                            if (j == data.startNumY)
                            {
                                strPosX = 0;
                                strPosY = data.Sy - j * data.Ho;
                                endPosX = data.Ex - i * data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else if (j == data.endNumY)
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Ex - i * data.Wo;
                                endPosY = data.Ey - j * data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Ex - i * data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region Middle
                        for (int j = data.startNumY; j <= data.endNumY; j++)
                        {
                            string path = input[i][j];
                            if (j == data.startNumY)
                            {
                                strPosX = 0;
                                strPosY = data.Sy - j * data.Ho;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else if (j == data.endNumY)
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ey - j * data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                        }
                        #endregion
                    }
                    box.Add(tempbox);
                }
            }

            return(box);
        }
Example #23
0
        static void Main(string[] args)
        {
            var qualityLevels = new Dictionary <int, int[, ]>
            {
                { 50, Q50 }
            };

            foreach (int level in new[] { 10, 20, 30, 40 })
            {
                int[,] newQ = new int[8, 8];
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        newQ[i, j] = (int)Math.Min(Q50[i, j] * (50d / level), 256d);
                    }
                }

                qualityLevels.Add(level, newQ);
            }
            foreach (int level in new[] { 60, 70, 80, 90, 95 })
            {
                int[,] newQ = new int[8, 8];
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        newQ[i, j] = (int)Math.Min(Q50[i, j] * ((100d - level) / 50d), 256d);
                    }
                }

                qualityLevels.Add(level, newQ);
            }

            var imageToMatrix = new ImageToMatrix();

            var bitmap = new Bitmap(File.OpenRead("sample_blackwhite.bmp"));

            double[,] output;
            imageToMatrix.Convert(bitmap, out output);

            var dct = GetDctMatrix();

            var matrixMultiplied = Matrix.Dot(output, dct);

            foreach (var q in qualityLevels)
            {
                double[,] rounded = new double[8, 8];
                for (int row = 0; row < 8; row++)
                {
                    for (int column = 0; column < 8; column++)
                    {
                        int divided         = (int)Math.Round(matrixMultiplied[row, column] * 256d / q.Value[row, column], 0);
                        int multipliedAgain = divided * q.Value[row, column];

                        rounded[row, column] = multipliedAgain / 256d;
                    }
                }

                var newMatrix = Matrix.Divide(rounded, dct);

                var mtoi = new MatrixToImage();

                Bitmap bitmap2;
                mtoi.Convert(newMatrix, out bitmap2);
                bitmap2.Save($"sample_blackwhite_q{q.Key}.bmp");
            }
        }
Example #24
0
        public void ConvertTest2()
        {
            // Load a test image
            Bitmap sourceImage = Properties.Resources.image1;

            // Make sure values are binary
            new Threshold().ApplyInPlace(sourceImage);

            // Create the converters
            ImageToMatrix imageToMatrix = new ImageToMatrix() { Min = 0, Max = 255 };
            MatrixToImage matrixToImage = new MatrixToImage() { Min = 0, Max = 255 };

            // Convert to matrix
            double[,] matrix; // initialization is not needed
            imageToMatrix.Convert(sourceImage, out matrix);

            // Revert to image
            Bitmap resultImage; // initialization is not needed
            matrixToImage.Convert(matrix, out resultImage);

            // Show both images, which should be equal
            // ImageBox.Show(sourceImage, PictureBoxSizeMode.Zoom);
            // ImageBox.Show(resultImage, PictureBoxSizeMode.Zoom);

            UnmanagedImage img1 = UnmanagedImage.FromManagedImage(sourceImage);
            UnmanagedImage img2 = UnmanagedImage.FromManagedImage(resultImage);

            List<IntPoint> p1 = img1.CollectActivePixels();
            List<IntPoint> p2 = img2.CollectActivePixels();

            bool equals = new HashSet<IntPoint>(p1).SetEquals(p2);

            Assert.IsTrue(equals);
        }
Example #25
0
        public void ConvertTest4()
        {
            ImageToMatrix target = new ImageToMatrix(min: 0, max: 255);
            Bitmap        image  = Accord.Imaging.Image.Clone(Properties.Resources.image3);

            Assert.AreEqual(PixelFormat.Format32bppArgb, image.PixelFormat);

            {
                double[,] output;
                double[,] outputExpected =
                {
                    { 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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
                };

                target.Channel = RGB.R;
                target.Convert(image, out output);

                for (int i = 0; i < outputExpected.GetLength(0); i++)
                {
                    for (int j = 0; j < outputExpected.GetLength(1); j++)
                    {
                        Assert.AreEqual(outputExpected[i, j], output[i, j]);
                    }
                }
            }

            {
                double[,] output;
                double[,] outputExpected =
                {
                    { 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,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 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
                };

                target.Channel = RGB.G;
                target.Convert(image, out output);

                for (int i = 0; i < outputExpected.GetLength(0); i++)
                {
                    for (int j = 0; j < outputExpected.GetLength(1); j++)
                    {
                        Assert.AreEqual(outputExpected[i, j], output[i, j]);
                    }
                }
            }

            {
                double[,] output;
                double[,] outputExpected =
                {
                    { 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,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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
                };

                target.Channel = RGB.B;
                target.Convert(image, out output);

                for (int i = 0; i < outputExpected.GetLength(0); i++)
                {
                    for (int j = 0; j < outputExpected.GetLength(1); j++)
                    {
                        Assert.AreEqual(outputExpected[i, j], output[i, j]);
                    }
                }
            }
        }
Example #26
0
        public void ConvertTest3()
        {
            double[] pixels = 
            {
                 0, 0, 0, 0,
                 0, 1, 1, 0,
                 0, 1, 1, 0,
                 0, 0, 0, 0,
            };


            ArrayToImage conv1 = new ArrayToImage(width: 4, height: 4);
            Bitmap 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 
            ImageToMatrix conv = new ImageToMatrix(min: 0, max: 1);

            // 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);
        }
Example #27
0
        public void ConvertTest4()
        {
            ImageToMatrix target = new ImageToMatrix(min: 0, max: 255);
            Bitmap image = Properties.Resources.image3;
            Assert.AreEqual(PixelFormat.Format32bppArgb, image.PixelFormat);

            {
                double[,] output;
                double[,] outputExpected =
                {
                     { 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 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
                };

                target.Channel = RGB.R;
                target.Convert(image, out output);

                for (int i = 0; i < outputExpected.GetLength(0); i++)
                    for (int j = 0; j < outputExpected.GetLength(1); j++)
                        Assert.AreEqual(outputExpected[i, j], output[i, j]);
            }

            {
                double[,] output;
                double[,] outputExpected =
                {
                     { 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,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 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
                };

                target.Channel = RGB.G;
                target.Convert(image, out output);

                for (int i = 0; i < outputExpected.GetLength(0); i++)
                    for (int j = 0; j < outputExpected.GetLength(1); j++)
                        Assert.AreEqual(outputExpected[i, j], output[i, j]);
            }

            {
                double[,] output;
                double[,] outputExpected =
                {
                     { 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,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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
                };

                target.Channel = RGB.B;
                target.Convert(image, out output);

                for (int i = 0; i < outputExpected.GetLength(0); i++)
                    for (int j = 0; j < outputExpected.GetLength(1); j++)
                        Assert.AreEqual(outputExpected[i, j], output[i, j]);
            }
        }
Example #28
0
        public void ConvertTest()
        {
            ImageToMatrix target = new ImageToMatrix(min: 0, max: 255);
            Bitmap image = Properties.Resources.image1;

            new Invert().ApplyInPlace(image);
            new Threshold().ApplyInPlace(image);

            double[,] output;
            double[,] outputExpected =
            {
                 { 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 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
            };


            target.Convert(image, out output);

            for (int i = 0; i < outputExpected.GetLength(0); i++)
                for (int j = 0; j < outputExpected.GetLength(1); j++)
                    Assert.AreEqual(outputExpected[i, j], output[i, j]);
        }
Example #29
0
        public void ConvertTest1()
        {
            MatrixToImage target = new MatrixToImage();

            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
            };

            Bitmap imageActual;
            target.Convert(pixels, out imageActual);


            double[,] actual;
            ImageToMatrix c = new ImageToMatrix();
            c.Convert(imageActual, out actual);

            double[,] expected;
            Bitmap imageExpected = Properties.Resources.image1;
            new Threshold().ApplyInPlace(imageExpected);
            new Invert().ApplyInPlace(imageExpected);
            c.Convert(imageExpected, out expected);


            for (int i = 0; i < pixels.GetLength(0); i++)
                for (int j = 0; j < pixels.GetLength(1); j++)
                    Assert.AreEqual(actual[i, j], expected[i, j]);
        }