Ejemplo n.º 1
0
 /// <summary>
 ///   Constructs a new Blend filter.
 /// </summary>
 /// 
 /// <param name="homography">The homography matrix mapping a second image to the overlay image.</param>
 /// <param name="overlayImage">The overlay image (also called the anchor).</param>
 /// 
 public Blend(MatrixH homography, Bitmap overlayImage)
 {
     this.homography = homography;
     this.overlayImage = overlayImage;
     formatTranslations[PixelFormat.Format8bppIndexed] = PixelFormat.Format32bppArgb;
     formatTranslations[PixelFormat.Format24bppRgb] = PixelFormat.Format32bppArgb;
     formatTranslations[PixelFormat.Format32bppArgb] = PixelFormat.Format32bppArgb;
 }
Ejemplo n.º 2
0
        private static void TestDecodingOfCorruptedVectors()
        {
            // G = 1 1 0 1 0 0
            //     0 1 1 0 1 0
            //     1 0 1 0 0 1
            var matrix = new int[3][];

            matrix[0] = new int[6] {
                1, 1, 0, 1, 0, 0
            };
            matrix[1] = new int[6] {
                0, 1, 1, 0, 1, 0
            };
            matrix[2] = new int[6] {
                1, 0, 1, 0, 0, 1
            };

            var matrixG = new MatrixG(
                length: matrix[0].GetUpperBound(0) + 1,
                dimension: matrix.GetUpperBound(0) + 1,
                matrix: matrix);

            // H = 1 0 0 1 0 1
            //     0 1 0 1 1 0
            //     0 0 1 0 1 1
            matrix    = new int[3][];
            matrix[0] = new int[6] {
                1, 0, 0, 1, 0, 1
            };
            matrix[1] = new int[6] {
                0, 1, 0, 1, 1, 0
            };
            matrix[2] = new int[6] {
                0, 0, 1, 0, 1, 1
            };

            var matrixH = new MatrixH(matrix);

            // 1. Word to encode
            var clean = new int[3] {
                0, 1, 0
            };
            var dirty = new int[3] {
                0, 1, 0
            };
            // 2. Encoded word with 'G'
            var encoded   = matrixG.Encode(clean);             // Encodes to 011010
            var corrupted = matrixG.Encode(dirty);             // Encodes to 011010
            // 3. Corrupt it
            var channel = new Channel(0.500121);

            corrupted = channel.SendVectorThrough(corrupted);
            // 4. Decode it
            var decoded = matrixH.Decode(corrupted);

            if (string.Join("", encoded) != string.Join("", decoded))
            {
                ConsoleHelper.WriteError($"{string.Join("", encoded)} does not equal {string.Join("", decoded)}.");
            }
            else
            {
                ConsoleHelper.WriteInformation("Matches.");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 ///   Constructs a new Blend filter.
 /// </summary>
 /// 
 /// <param name="homography">The homography matrix mapping a second image to the overlay image.</param>
 /// 
 public Rectification(MatrixH homography)
 {
     this.homography = homography;
     formatTranslations[PixelFormat.Format8bppIndexed] = PixelFormat.Format8bppIndexed;
     formatTranslations[PixelFormat.Format24bppRgb] = PixelFormat.Format24bppRgb;
     formatTranslations[PixelFormat.Format32bppArgb] = PixelFormat.Format32bppArgb;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// The blending filter is able to blend two images using a homography matrix.
        /// A linear alpha gradient is used to smooth out differences between the two
        /// images, effectively blending them in two images. The gradient is computed
        /// considering the distance between the centers of the two images.
        /// </summary>
        /// <param name="im">Image.</param>
        /// <param name="overlayIm">The overlay image (also called the anchor).</param>
        /// <param name="homography">Homography matrix used to map a image passed to
        /// the filter to the overlay image specified at filter creation.</param>
        /// <param name="fillColor">The filling color used to fill blank spaces. The filling color will only be visible after the image is converted
        /// to 24bpp. The alpha channel will be used internally by the filter.</param>
        /// <param name="gradient">A value indicating whether to blend using a linear
        ///  gradient or just superimpose the two images with equal weights.</param>
        /// <param name="alphaOnly">A value indicating whether only the alpha channel
        /// should be blended. This can be used together with a transparency
        /// mask to selectively blend only portions of the image.</param>
        /// <returns>Blended image.</returns>
        internal static Image <TColorDest, TDepth> Blend <TColorSrc, TColorDest, TDepth>(this Image <TColorSrc, TDepth> im, Image <TColorSrc, TDepth> overlayIm, MatrixH homography, TColorDest fillColor, bool gradient = true, bool alphaOnly = false)
            where TColorSrc : IColor
            where TColorDest : IColor4
            where TDepth : struct
        {
            var overlay = overlayIm.ToBitmap(copyAlways: false, failIfCannotCast: true);

            Blend blend = new Blend(homography, overlay);

            blend.AlphaOnly = alphaOnly;
            blend.Gradient  = gradient;
            blend.FillColor = fillColor.ToColor();

            return(im.ApplyFilter <TColorSrc, TDepth, TColorDest>(blend));
        }
Ejemplo n.º 5
0
        private static void TestMatrixH()
        {
            // G = 1 1 0 1 0 0
            //     0 1 1 0 1 0
            //     1 0 1 0 0 1
            var matrix = new int[3][];

            matrix[0] = new int[6] {
                1, 1, 0, 1, 0, 0
            };
            matrix[1] = new int[6] {
                0, 1, 1, 0, 1, 0
            };
            matrix[2] = new int[6] {
                1, 0, 1, 0, 0, 1
            };

            var matrixG = new MatrixG(
                length: matrix[0].GetUpperBound(0) + 1,
                dimension: matrix.GetUpperBound(0) + 1,
                matrix: matrix);

            // H = 1 0 0 1 0 1
            //     0 1 0 1 1 0
            //     0 0 1 0 1 1
            //var matrixH = matrixG.GetMatrixH();
            matrix    = new int[3][];
            matrix[0] = new int[6] {
                1, 0, 0, 1, 0, 1
            };
            matrix[1] = new int[6] {
                0, 1, 0, 1, 1, 0
            };
            matrix[2] = new int[6] {
                0, 0, 1, 0, 1, 1
            };

            // Todo: the GetMatrixH() cannot properly convert from this 'G'.
            var matrixH = new MatrixH(matrix);

            matrixG.DisplayMatrix();
            matrixH.DisplayMatrix();

            var toSyndrome1 = new int[6] {
                0, 0, 0, 0, 0, 0
            };
            var toSyndrome2 = new int[6] {
                0, 0, 0, 0, 0, 1
            };
            var toSyndrome3 = new int[6] {
                0, 0, 0, 0, 1, 0
            };
            var toSyndrome4 = new int[6] {
                0, 0, 0, 1, 0, 0
            };
            var toSyndrome5 = new int[6] {
                0, 0, 1, 0, 0, 0
            };
            var toSyndrome6 = new int[6] {
                0, 1, 0, 0, 0, 0
            };
            var toSyndrome7 = new int[6] {
                1, 0, 0, 0, 0, 0
            };
            var toSyndrome8 = new int[6] {
                0, 0, 1, 1, 0, 0
            };

            var syndrome1 = string.Join("", matrixH.GetSyndrome(toSyndrome1));
            var syndrome2 = string.Join("", matrixH.GetSyndrome(toSyndrome2));
            var syndrome3 = string.Join("", matrixH.GetSyndrome(toSyndrome3));
            var syndrome4 = string.Join("", matrixH.GetSyndrome(toSyndrome4));
            var syndrome5 = string.Join("", matrixH.GetSyndrome(toSyndrome5));
            var syndrome6 = string.Join("", matrixH.GetSyndrome(toSyndrome6));
            var syndrome7 = string.Join("", matrixH.GetSyndrome(toSyndrome7));
            var syndrome8 = string.Join("", matrixH.GetSyndrome(toSyndrome8));

            var syndromes = new List <string> {
                syndrome1, syndrome2, syndrome3, syndrome4, syndrome5, syndrome6, syndrome7, syndrome8
            };
            var outcomes = new List <string> {
                "000", "101", "011", "110", "001", "010", "100", "111"
            };

            for (var i = 0; i < syndromes.Count; i++)
            {
                if (syndromes[i] != outcomes[i])
                {
                    ConsoleHelper.WriteError("'MatrixH' calculates syndromes improperly.");
                }
            }


            var toEncode1 = new int[] { 0, 0, 0 };
            var toEncode2 = new int[] { 1, 0, 0 };
            var toEncode3 = new int[] { 0, 1, 0 };
            var toEncode4 = new int[] { 0, 0, 1 };
            var toEncode5 = new int[] { 1, 1, 0 };
            var toEncode6 = new int[] { 0, 1, 1 };
            var toEncode7 = new int[] { 1, 0, 1 };
            var toEncode8 = new int[] { 1, 1, 1 };

            var encoded1 = string.Join("", matrixG.Encode(toEncode1));
            var encoded2 = string.Join("", matrixG.Encode(toEncode2));
            var encoded3 = string.Join("", matrixG.Encode(toEncode3));
            var encoded4 = string.Join("", matrixG.Encode(toEncode4));
            var encoded5 = string.Join("", matrixG.Encode(toEncode5));
            var encoded6 = string.Join("", matrixG.Encode(toEncode6));
            var encoded7 = string.Join("", matrixG.Encode(toEncode7));
            var encoded8 = string.Join("", matrixG.Encode(toEncode8));
            var encoded  = new List <string> {
                encoded1, encoded2, encoded3, encoded4, encoded5, encoded6, encoded7, encoded8
            };

            outcomes = new List <string> {
                "000000", "110100", "011010", "101001", "101110", "110011", "011101", "000111"
            };
            for (var i = 0; i < encoded.Count; i++)
            {
                if (encoded[i] != outcomes[i])
                {
                    ConsoleHelper.WriteError("'MatrixG' encodes vectors improperly.");
                }
            }


            var decoded1 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode1))));
            var decoded2 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode2))));
            var decoded3 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode3))));
            var decoded4 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode4))));
            var decoded5 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode5))));
            var decoded6 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode6))));
            var decoded7 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode7))));
            var decoded8 = string.Join("", matrixG.Decode(matrixH.Decode(matrixG.Encode(toEncode8))));
            var decoded  = new List <string> {
                decoded1, decoded2, decoded3, decoded4, decoded5, decoded6, decoded7, decoded8
            };

            outcomes = new List <string> {
                "000", "100", "010", "001", "110", "011", "101", "111"
            };
            for (var i = 0; i < decoded.Count; i++)
            {
                if (decoded[i] != outcomes[i])
                {
                    ConsoleHelper.WriteError("'MatrixH' decodes vectors improperly.");
                }
            }
        }
Ejemplo n.º 6
0
        public void Panorama_Example1()
        {
            Accord.Math.Random.Generator.Seed = 0;

            // Let's start with two pictures that have been
            // taken from slightly different points of view:
            //
            Bitmap img1 = Accord.Imaging.Image.Clone(Resources.dc_left);
            Bitmap img2 = Accord.Imaging.Image.Clone(Resources.dc_right);

            // Those pictures are shown below:
            // ImageBox.Show(img1, PictureBoxSizeMode.Zoom, 640, 480);
            // ImageBox.Show(img2, PictureBoxSizeMode.Zoom, 640, 480);


            // Step 1: Detect feature points using Surf Corners Detector
            var surf = new SpeededUpRobustFeaturesDetector();

            var points1 = surf.ProcessImage(img1);
            var points2 = surf.ProcessImage(img2);

            // Step 2: Match feature points using a k-NN
            var matcher = new KNearestNeighborMatching(5);
            var matches = matcher.Match(points1, points2);

            // Step 3: Create the matrix using a robust estimator
            var     ransac           = new RansacHomographyEstimator(0.001, 0.99);
            MatrixH homographyMatrix = ransac.Estimate(matches);

            Assert.AreEqual(1.15707409, homographyMatrix.Elements[0], 1e-5);
            Assert.AreEqual(-0.0233834628, homographyMatrix.Elements[1], 1e-5);
            Assert.AreEqual(-261.8217, homographyMatrix.Elements[2], 1e-2);
            Assert.AreEqual(0.08801343, homographyMatrix.Elements[3], 1e-5);
            Assert.AreEqual(1.12451434, homographyMatrix.Elements[4], 1e-5);
            Assert.AreEqual(-171.191208, homographyMatrix.Elements[5], 1e-2);
            Assert.AreEqual(0.000127789128, homographyMatrix.Elements[6], 1e-5);
            Assert.AreEqual(0.00006173445, homographyMatrix.Elements[7], 1e-5);
            Assert.AreEqual(8, homographyMatrix.Elements.Length);


            // Step 4: Project and blend using the homography
            Blend blend = new Blend(homographyMatrix, img1);


            // Compute the blending algorithm
            Bitmap result = blend.Apply(img2);

            // Show on screen
            // ImageBox.Show(result, PictureBoxSizeMode.Zoom, 640, 480);


            result = Accord.Imaging.Image.Clone(result);

#if NET35
            // result.Save(@"C:\Projects\Accord.NET\framework\Unit Tests\Accord.Tests.Imaging\Resources\blend_net35.png", ImageFormat.Png);
            Bitmap image = Accord.Imaging.Image.Clone(Resources.blend_net35);
#else
            // result.Save(@"C:\Projects\Accord.NET\framework\Unit Tests\Accord.Tests.Imaging\Resources\blend_net45.png", ImageFormat.Png);
            Bitmap image = Accord.Imaging.Image.Clone(Resources.blend_net45);
#endif

            double[,] expected; new ImageToMatrix().Convert(image, out expected);
            double[,] actual; new ImageToMatrix().Convert(result, out actual);
            Assert.IsTrue(Matrix.IsEqual(expected, actual, atol: 0.1));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// The blending filter is able to blend two images using a homography matrix.
 /// A linear alpha gradient is used to smooth out differences between the two
 /// images, effectively blending them in two images. The gradient is computed
 /// considering the distance between the centers of the two images.
 /// </summary>
 /// <param name="im">Image.</param>
 /// <param name="overlayIm">The overlay image (also called the anchor).</param>
 /// <param name="homography">Homography matrix used to map a image passed to
 /// the filter to the overlay image specified at filter creation.</param>
 /// <param name="fillColor">The filling color used to fill blank spaces. The filling color will only be visible after the image is converted
 /// to 24bpp. The alpha channel will be used internally by the filter.</param>
 /// <param name="gradient">A value indicating whether to blend using a linear
 ///  gradient or just superimpose the two images with equal weights.</param>
 /// <param name="alphaOnly">A value indicating whether only the alpha channel
 /// should be blended. This can be used together with a transparency
 /// mask to selectively blend only portions of the image.</param>
 /// <returns>Blended image.</returns>
 public static Image <TColorDest, byte> Blend <TColorSrc, TColorDest>(this Image <TColorSrc, byte> im, Image <TColorSrc, byte> overlayIm, MatrixH homography, TColorDest fillColor, bool gradient = true, bool alphaOnly = false)
     where TColorSrc : IColor4
     where TColorDest : IColor4
 {
     return(im.Blend <TColorSrc, TColorDest, byte>(overlayIm, homography, fillColor, gradient, alphaOnly));
 }
Ejemplo n.º 8
0
        public void ApplyTest2()
        {
            var img1 = Accord.Imaging.Image.Clone(Resources.image2);
            var img2 = Accord.Imaging.Image.Clone(Resources.image2);

            var img3 = Accord.Imaging.Image.Clone(Resources.image2);
            var img4 = Accord.Imaging.Image.Clone(Resources.image2);


            MatrixH homography;
            Blend   blend;

            homography = new MatrixH(1, 0, 32,
                                     0, 1, 0,
                                     0, 0);


            blend = new Blend(homography, img1);
            var img12 = blend.Apply(img2);

            //ImageBox.Show("Blend of 1 and 2", img12, PictureBoxSizeMode.Zoom);
            Assert.AreEqual(img12.PixelFormat, PixelFormat.Format32bppArgb);

            blend = new Blend(homography, img3);
            var img34 = blend.Apply(img4);

            //ImageBox.Show("Blend of 3 and 4", img34, PictureBoxSizeMode.Zoom);
            Assert.AreEqual(img34.PixelFormat, PixelFormat.Format32bppArgb);


            homography = new MatrixH(1, 0, 64,
                                     0, 1, 0,
                                     0, 0);


            blend = new Blend(homography, img12);
            var img1234 = blend.Apply(img34);

            //ImageBox.Show("Blend of 1, 2, 3, 4", img1234, PictureBoxSizeMode.Zoom);
            Assert.AreEqual(img1234.PixelFormat, PixelFormat.Format32bppArgb);



            // Blend of 1 and 5 (8bpp and 32bpp)
            homography = new MatrixH(1, 0, 0,
                                     0, 1, 32,
                                     0, 0);


            //ImageBox.Show("Image 1", img1, PictureBoxSizeMode.Zoom);
            blend = new Blend(homography, img1234);
            var img15 = blend.Apply(img1);

            //ImageBox.Show("Blend of 1 and 5", img15, PictureBoxSizeMode.Zoom);

            Assert.AreEqual(img1234.PixelFormat, PixelFormat.Format32bppArgb);
            Assert.AreEqual(img1.PixelFormat, PixelFormat.Format8bppIndexed);
            Assert.AreEqual(img15.PixelFormat, PixelFormat.Format32bppArgb);
            Assert.AreEqual(128, img15.Width);
            Assert.AreEqual(64, img15.Height);
        }
Ejemplo n.º 9
0
        public void ApplyTest()
        {
            Bitmap img1 = Properties.Resources.image2;


            MatrixH homography = new MatrixH(1, 0, 32,
                                             0, 1, 0,
                                             0, 0);

            ProjectiveTransform transform = new ProjectiveTransform(homography);

            transform.FillColor = Color.Red;
            Bitmap actual = transform.Apply(img1);

            ImageBox.Show(actual, PictureBoxSizeMode.Zoom);

            Assert.AreEqual(64, actual.Size.Width);
            Assert.AreEqual(32, actual.Size.Height);



            homography = new MatrixH(2, 0, 0,
                                     0, 2, 0,
                                     0, 0);

            transform           = new ProjectiveTransform(homography);
            transform.FillColor = Color.Red;
            actual = transform.Apply(img1);

            ImageBox.Show(actual, PictureBoxSizeMode.Zoom);

            Assert.AreEqual(32, actual.Size.Width);
            Assert.AreEqual(32, actual.Size.Height);



            homography = new MatrixH(2, 0, 32,
                                     0, 0.5f, 32,
                                     0, 0);

            transform           = new ProjectiveTransform(homography);
            transform.FillColor = Color.Red;
            actual = transform.Apply(img1);

            ImageBox.Show(actual, PictureBoxSizeMode.Zoom);

            Assert.AreEqual(32 / 2 + 32, actual.Size.Width);
            Assert.AreEqual(32 / 0.5 + 32, actual.Size.Height);



            homography = new MatrixH(1, 0, -32,
                                     0, 1, 0,
                                     0, 0);

            transform           = new ProjectiveTransform(homography);
            transform.FillColor = Color.Red;
            actual = transform.Apply(img1);

            ImageBox.Show(actual, PictureBoxSizeMode.Zoom);

            Assert.AreEqual(64, actual.Size.Width);
            Assert.AreEqual(32, actual.Size.Height);
        }
Ejemplo n.º 10
0
        public void Load(string fileName)
        {
            FileStream   strm   = new FileStream(fileName, FileMode.Open);
            StreamReader reader = new StreamReader(strm);

            // read header
            string rawLine = reader.ReadLine();
            int    counter = 0;

            while ((rawLine = reader.ReadLine()) != null)
            {
                string[] elements = rawLine.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                double parameter1 = Convert.ToDouble(elements[1]);
                double parameter2 = Convert.ToDouble(elements[2]);

                Line2D line = new Line2D(parameter1, parameter2, counter < m_rows);
                if (counter < m_rows)
                {
                    m_rowLines.Add(line);
                }
                else
                {
                    m_columnLines.Add(line);
                }

                counter++;
            }

            // now do the intersections
            for (int i = 0; i < m_rows; i++)
            {
                Line2D row = m_rowLines[i];
                for (int j = 0; j < m_cols; j++)
                {
                    Line2D column       = m_columnLines[j];
                    Point? intersection = row.IntersectWith(column);

                    if (intersection != null)
                    {
                        m_gridPoints[i, j] = intersection.Value;
                    }
                }
            }

            // now fill the polygons
            RansacHomographyEstimator ransac = new RansacHomographyEstimator(0.001, 0.99);

            for (int i = 0; i < m_rows - 1; i++)
            {
                for (int j = 0; j < m_cols - 1; j++)
                {
                    m_polygons[i, j] = new Polygon2D();
                    m_polygons[i, j].Points.Add(m_gridPoints[i, j]);
                    m_polygons[i, j].Points.Add(m_gridPoints[i, j + 1]);
                    m_polygons[i, j].Points.Add(m_gridPoints[i + 1, j + 1]);
                    m_polygons[i, j].Points.Add(m_gridPoints[i + 1, j]);

                    if (Constants.DebugPrint)
                    {
                        Debug.WriteLine("\tPolygon:");
                        Debug.WriteLine("\t\t" + m_polygons[i, j].Points[0]);
                        Debug.WriteLine("\t\t" + m_polygons[i, j].Points[1]);
                        Debug.WriteLine("\t\t" + m_polygons[i, j].Points[2]);
                        Debug.WriteLine("\t\t" + m_polygons[i, j].Points[3]);
                    }

                    Accord.Point[] templatePts = new Accord.Point[4];
                    templatePts[0] = new Accord.Point(j / (float)(m_cols - 1), i / (float)(m_rows - 1));
                    templatePts[1] = new Accord.Point((j + 1) / (float)(m_cols - 1), i / (float)(m_rows - 1));
                    templatePts[2] = new Accord.Point((j + 1) / (float)(m_cols - 1), (i + 1) / (float)(m_rows - 1));
                    templatePts[3] = new Accord.Point(j / (float)(m_cols - 1), (i + 1) / (float)(m_rows - 1));

                    Accord.Point[] realPoints = new Accord.Point[4];
                    for (int k = 0; k < 4; k++)
                    {
                        realPoints[k] = new Accord.Point((float)m_polygons[i, j].Points[k].X, (float)m_polygons[i, j].Points[k].Y);
                    }

                    Accord.Point[][] matchedPoints = new Accord.Point[2][];
                    matchedPoints[1] = templatePts;
                    matchedPoints[0] = realPoints;

                    MatrixH homography = ransac.Estimate(matchedPoints);
                    m_homographies.Add(m_polygons[i, j], homography);
                }
            }

            reader.Close();
            reader.Dispose();
            reader = null;

            strm.Close();
            strm.Dispose();
            strm = null;
        }
Ejemplo n.º 11
0
        public void Panorama_Example1()
        {
            Accord.Math.Tools.SetupGenerator(0);

            // Let's start with two pictures that have been
            // taken from slightly different points of view:
            //
            Bitmap img1 = Resources.dc_left;
            Bitmap img2 = Resources.dc_right;

            // Those pictures are shown below:
            // ImageBox.Show(img1, PictureBoxSizeMode.Zoom, 640, 480);
            // ImageBox.Show(img2, PictureBoxSizeMode.Zoom, 640, 480);


            // Step 1: Detect feature points using Surf Corners Detector
            var surf = new SpeededUpRobustFeaturesDetector();

            var points1 = surf.ProcessImage(img1);
            var points2 = surf.ProcessImage(img2);

            // Step 2: Match feature points using a k-NN
            var matcher = new KNearestNeighborMatching(5);
            var matches = matcher.Match(points1, points2);

            // Step 3: Create the matrix using a robust estimator
            var     ransac           = new RansacHomographyEstimator(0.001, 0.99);
            MatrixH homographyMatrix = ransac.Estimate(matches);

            Assert.AreEqual(1.15707409, homographyMatrix.Elements[0], 1e-5);
            Assert.AreEqual(-0.0233834628, homographyMatrix.Elements[1], 1e-5);
            Assert.AreEqual(-261.8217, homographyMatrix.Elements[2], 1e-2);
            Assert.AreEqual(0.08801343, homographyMatrix.Elements[3], 1e-5);
            Assert.AreEqual(1.12451434, homographyMatrix.Elements[4], 1e-5);
            Assert.AreEqual(-171.191208, homographyMatrix.Elements[5], 1e-2);
            Assert.AreEqual(0.000127789128, homographyMatrix.Elements[6], 1e-5);
            Assert.AreEqual(0.00006173445, homographyMatrix.Elements[7], 1e-5);
            Assert.AreEqual(8, homographyMatrix.Elements.Length);


            // Step 4: Project and blend using the homography
            Blend blend = new Blend(homographyMatrix, img1);


            // Compute the blending algorithm
            Bitmap result = blend.Apply(img2);

            // Show on screen
            // ImageBox.Show(result, PictureBoxSizeMode.Zoom, 640, 480);

            //result.Save(@"C:\Projects\Accord.NET\net35.png", ImageFormat.Png);

#if NET35
            Bitmap image = Properties.Resources.blend_net35;
#else
            Bitmap image = Properties.Resources.blend_net45;
#endif

#pragma warning disable 618
            double[,] expected = image.ToDoubleMatrix(0);
            double[,] actual   = result.ToDoubleMatrix(0);
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.1));
#pragma warning restore 618
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            var vector = File.ReadAllBytes("C:\\test.bmp");
            int i      = 5;

            #region Creation of matrices.
            var matrix = new List <List <byte> >(2)
            {
                new List <byte> {
                    1, 0, 1, 1, 0
                },
                new List <byte> {
                    0, 1, 0, 1, 1
                }
            };
            var matrixG = new MatrixG(length: matrix[0].Count,
                                      dimension: matrix.Count,
                                      matrix: matrix);

            matrix = new List <List <byte> >(3)
            {
                new List <byte> {
                    1, 0, 1, 0, 0
                },
                new List <byte> {
                    1, 1, 0, 1, 0
                },
                new List <byte> {
                    0, 1, 0, 0, 1
                }
            };
            var matrixH = new MatrixH(matrix);
            #endregion

            //var channel = new Channel(0.09);

            //var text = "Some sample text.";
            //// This will contain something like: 89, 112, 201, 5, ...
            //var textAsBytes = Encoding.ASCII.GetBytes(text);
            //var stringBuilder = new StringBuilder();

            //// 1. Convert the text into a string made up of binary symbols.
            //foreach (var word in textAsBytes)
            //{
            //	var @byte = Convert.ToString(value: word, toBase: 2)
            //					   .PadLeft(totalWidth: 8, paddingChar: '0');
            //	stringBuilder.Append(@byte);
            //}

            //// 2. Split it into length that matches the dimension of the matrix.
            //var addedExtra = 0;
            //var rows = 2;
            //var textInBinary = stringBuilder.ToString();
            //stringBuilder = stringBuilder.Clear();
            //for (var c = 0; c < textInBinary.Length;)
            //{
            //	var toEncodeAsString = string.Empty;
            //	for (var r = 0; r < rows; r++)
            //	{
            //		if (c == textInBinary.Length)
            //		{
            //			toEncodeAsString += '0';
            //			addedExtra++;
            //		}
            //		else
            //		{
            //			toEncodeAsString += textInBinary[c];
            //			c++; // Move to the next bit.
            //		}
            //	}

            //	// 3. Encode the word.
            //	var toEncodeAsList = ConvertStringToByteList(toEncodeAsString);
            //	var encoded = matrixG.Encode(toEncodeAsList);

            //	// 4. Send it through the channel.
            //	var deformed = channel.SendVectorThrough(encoded);

            //	// 5. Decode the vector.
            //	var decoded = matrixH.Decode(deformed);

            //	// 6. Get the original word.
            //	var fullyDecoded = matrixG.Decode(decoded);

            //	// 7. Put it all into a string.
            //	stringBuilder.Append(ConvertByteListToString(fullyDecoded));
            //}

            //textInBinary = stringBuilder.ToString();
            //var index = 0;
            //var decodedTextAsList = new List<byte>();
            //// 8. Convert it back in to numbers.
            //for (var i = 0; i < textInBinary.Length;)
            //{
            //	// 8.1 Put it in to groups of 8 bits.
            //	var byteAsBinaryString = string.Empty;
            //	for (var c = 0; c < 8; c++)
            //	{
            //		if (i == textInBinary.Length)
            //		{
            //			//byteAsBinaryString += '0';
            //			c++;
            //		}
            //		else
            //		{
            //			byteAsBinaryString += textInBinary[i];
            //			i++;
            //		}
            //	}

            //	// 8.2 Convert it to a decimal number.
            //	var byteAsDecimalString = Convert.ToByte(byteAsBinaryString, 2);
            //	decodedTextAsList.Add(byteAsDecimalString);
            //}

            //var revertedText = Encoding.ASCII.GetString(decodedTextAsList.ToArray());
            //Console.WriteLine(revertedText);

            Console.ReadKey();
        }