Esempio n. 1
0
        /// <summary>
        /// Load in the image matrix by getting the substrokes from the file
        /// </summary>
        /// <param name="filename">JNT file to grab substrokes from</param>
        private void loadJournal(string filename)
        {
            Substrokes substrokes = new Substrokes((new ConverterJnt.ReadJnt(filename)).Sketch.Substrokes);

            //addDefinition(substrokes, filename);
            addDefinition(substrokes);
        }
Esempio n. 2
0
        /// <summary>
        /// Add the image created by substrokes into the current image, no normalize
        /// </summary>
        /// <param name="substrokes">Substrokes to add to current image</param>
        private void addDefinition(Substrokes substrokes)
        {
            DefinitionImage di = new DefinitionImage(m_width, m_height, substrokes);

            m_image.matrix.Add(di.m_image.matrix);
            m_polar.matrix.Add(di.m_polar.matrix);
            m_imageTransform.matrix.Add(di.m_imageTransform.matrix);
            m_polarTransform.matrix.Add(di.m_polarTransform.matrix);

            //for single images
            m_rotatedImages = di.m_rotatedImages;

            //This is used to specify that all of the following images should match the first images orientation.
            //This is particularly useful when creating the average image ;)!
            if (m_matches.Count == 0)
            {
                m_matches.Add(di);
            }

            if (true)
            {
                di.Main.writeToBitmap("main" + counter.ToString() + ".bmp");
                di.Polar.writeToBitmap("polar" + counter.ToString() + ".bmp");
            }
            ++counter;

            /* Do not normalize here.
             * We will do that after the whole list from addDefinition(List<>) has been added.
             */
        }
Esempio n. 3
0
        /// <summary>
        /// Load in the image matrix by getting the substrokes from the file
        /// </summary>
        /// <param name="filename">XML file to grab substrokes from</param>
        private void loadXML(string filename)
        {
            Substrokes substrokes = new Substrokes((new ConverterXML.ReadXML(filename)).Sketch.Substrokes);

            //addDefinition(substrokes, filename);
            addDefinition(substrokes);
        }
Esempio n. 4
0
        private void addDefinition(Substrokes substrokes, DefinitionImage matchTo)
        {
            DefinitionImage di = new DefinitionImage(m_width, m_height, substrokes, matchTo);

            m_image.matrix.Add(di.m_image.matrix);
            m_polar.matrix.Add(di.m_polar.matrix);
            m_imageTransform.matrix.Add(di.m_imageTransform.matrix);
            m_polarTransform.matrix.Add(di.m_polarTransform.matrix);

            if (true)
            {
                di.Main.writeToBitmap("out" + counter.ToString() + ".bmp");
            }
            ++counter;
        }
Esempio n. 5
0
        private void addDefinition(Substrokes substrokes, string filename)
        {
            /*
             * int index = indexOf(filename);
             * if (filename != null && index > -1)
             * {
             *  addDefinition(substrokes, DefinitionImage.m_matches[index]);
             * }
             * else*/
            addDefinition(substrokes);

            /* Do not normalize here.
             * We will do that after the whole list from addDefinition(List<>) has been added.
             */
        }
Esempio n. 6
0
        /// <summary>
        /// Adds a group of substrokes to the image
        /// </summary>
        /// <param name="substrokes">The substrokes to add</param>
        protected virtual void AddPixels(Substrokes substrokes)
        {
            #if WEIGHTEDCENTER
            float max    = substrokes.MaxToWeightedCenter;
            Point center = substrokes.WeightedCenter;
            #else
            float max    = substrokes.MaxToCenter;
            Point center = substrokes.Center;
            #endif

            _weighted_center = center;

            span = 4 * max + 1.0f;

            int     row = -1, col = -1, rowprev = -1, colprev = -1;
            Point[] points;
            //Point center = substrokes.Center;
            for (int i = 0; i < substrokes.Length; ++i)
            {
                points = substrokes[i].Points;
                for (int j = 0; j < points.Length; ++j)
                {
                    //override GetCoordinates in derived children
                    //to get different coordinate system, such as
                    //polar, as in PolarImage
                    GetCoordinates(center, span, points[j], out row, out col);
                    this.matrix[row, col] = 1.0;

                    //If this pixel and previous pixel do not touch, add a straight line
                    //If the pixels are too far, dont connect them
                    if ((Math.Abs(col - colprev) > 1 || Math.Abs(row - rowprev) > 1) && j > 0 &&
                        Math.Abs(col - colprev) < _width / 2.0 && Math.Abs(row - rowprev) < _height / 2.0)
                    {
                        FillInLine(row, col, rowprev, colprev);
                    }

                    rowprev = row;
                    colprev = col;
                }
            }
            _cached_distances = null;
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a windowed image.
        /// </summary>
        /// <param name="keys">The substrokes that are being considered.</param>
        /// <param name="uncropped">The substrokes in the neighborhood of key (key is included in this list)</param>
        /// <param name="cropMethod">An enum that specifies the cropping metric.</param>
        public void CreateImage(List <Substroke> keys, List <Substroke> uncropped, CropMethod cropMethod)
        {
            // Creates a wrapper for the list of substrokes.
            keysSub = new Substrokes(keys);

            // Finds the maximum distance from the weighted center of the keys to the points on the substrokes of keys.
            float maxDist = float.NegativeInfinity;

            foreach (Substroke sub in keysSub.SubStrokes)
            {
                foreach (Point point in sub.PointsL)
                {
                    maxDist = Math.Max(maxDist, (float)(new PointDistance(keysSub.WeightedCenter, point).distance(PointDistance.EUCLIDIAN)));
                }
            }

            // Determines the width and height of keys
            this.keysWidth  = keysSub.MaxX - keysSub.MinX;
            this.keysHeight = keysSub.MaxY - keysSub.MinY;

            // Find the appropriate span given the size of the bounding box or the distance threshold
            if (cropMethod == CropMethod.RECTANGLE || cropMethod == CropMethod.SQUARE)
            {
                this.span = Math.Max(2 * Math.Max((float)(keysWidth / 2 + keysWidth * BB_THRESHOLD),
                                                  (float)(keysHeight / 2 + keysHeight * BB_THRESHOLD)) + 1.0f, 2 * maxDist + 1.0f);
            }
            else
            {
                this.span = Math.Max(Math.Max(keysWidth, keysHeight) + 2 * DISTANCE_THRESHOLD + 1.0f,
                                     2 * maxDist + 2 * DISTANCE_THRESHOLD + 1.0f);
            }

            this.cropped = this.CropSubstrokesDist(uncropped);

            //Trick it so it does not rotate
            //List<DefinitionImage> matches = new List<DefinitionImage>(0);
            //di = new DefinitionImage(this.iWidth, this.iHeight, this.cropped, matches);

            //this.AddPixels(cropped);
        }
Esempio n. 8
0
        public DefinitionImage(int width, int height, Substrokes substrokes, List <DefinitionImage> matches)
        {
            /* Note: this constructor is a special case, which does not normalize the values.
             * This constructor is important, as it is called in addDefinition(Substroke[] substrokes).
             * If we made this constructor more generic, we would crash with a stack overflow.
             *
             * ie. We cannot simple do this:
             * addDefinition(substrokes);
             */

            m_width  = width;
            m_height = height;

            m_image          = new Image(m_width, m_height, substrokes);
            m_polar          = new PolarImage(m_width, m_height, substrokes);
            m_imageTransform = new TransformImage(m_image);
            m_polarTransform = new TransformImage(m_polar);

            int len = matches.Count;

            //Find the rotated image for each
            if (len > 0)
            {
                double[] angles;
                m_polar.findTranslations(matches, out angles);

                m_rotatedImages = new Image[len];

                int        i;
                Substrokes temp;
                for (i = 0; i < len; ++i)
                {
                    temp = substrokes.rotateClone(angles[i]);
                    m_rotatedImages[i] = new Image(m_width, m_height, temp);
                }
            }
        }
Esempio n. 9
0
 public DefinitionImage(int width, int height, Substrokes substrokes, DefinitionImage matchTo)
     : this(width, height, substrokes, new List <DefinitionImage>(new DefinitionImage[] { matchTo }))
 {
 }
Esempio n. 10
0
 /// <summary>
 /// Constructor, no normalization
 /// </summary>
 /// <param name="width">Width of image in pixels</param>
 /// <param name="height">Height of image in pixels</param>
 /// <param name="substrokes">Substrokes to create the images</param>
 public DefinitionImage(int width, int height, Substrokes substrokes)
     : this(width, height, substrokes, DefinitionImage.m_matches)
 {
 }
Esempio n. 11
0
 public TransformImage(int width, int height, Substrokes substrokes)
     : this(new Image(width, height, substrokes))
 {
 }
Esempio n. 12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="width">Width in pixels</param>
 /// <param name="height">Height in pixels</param>
 /// <param name="substrokes">Substrokes to convert into the image</param>
 public PolarImage(int width, int height, Substrokes substrokes)
     : base(width, height, substrokes)
 {
 }
Esempio n. 13
0
 private void LoadImage(Substrokes substrokes)
 {
     AddPixels(substrokes);
 }
Esempio n. 14
0
 /// <summary>
 /// Creates an image from a group of substrokes
 /// </summary>
 /// <param name="width">The width of the image in pixels</param>
 /// <param name="height">The height of the image in pixels</param>
 /// <param name="substrokes">The group of substrokes to be rasterized</param>
 public Image(int width, int height, Substrokes substrokes)
     : this(width, height, DEFAULT_FILL)
 {
     LoadImage(substrokes);
 }
Esempio n. 15
0
        /*
         * /// <summary>
         * /// The definition image.
         * /// </summary>
         * private DefinitionImage di;
         */

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor for WindowedImage.
        /// </summary>
        /// <param name="width">The width of the image in pixels.</param>
        /// <param name="height">The height of the image in pixels.</param>
        public WindowedImage(int width, int height) : base(width, height)
        {
            this.cropped = new Substrokes();
        }