Ejemplo n.º 1
0
        public void AddSeam(Seam seam)
        {
            for (int i = len - 1; i >= 0; --i)
            {
                List<int> list = seams[len - i - 1];
                list.Add(seam[i]);
                Sort(list);
            }

            ++seamsCount;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to find vertical (up-down) seam with minimal energy
        /// </summary>
        /// <param name="number">how many seams needed</param>
        /// <returns>object representing founded seams</returns>
        SeamList FindVerticalSeams(int need)
        {
            int dx;
            int height = tmpHeight;
            int last = height - 1;
            List<int> blacklist = new List<int>(need);

            SeamList founded_seams = new SeamList(height, SeamList.SeamType.Vertical);

            while (founded_seams.Count != need)
            {
                Seam seam = new Seam(tmpHeight);

                // find start index
                dx = minEnergy();

                // no other minimum - quit
                if (dx == -1 || blacklist.Contains(dx))
                    break;

                seam.PushBack(dx);
                blacklist.Add(dx); // mark as visited

                // build minimum seam (going up)
                ulong min;
                int minIndex = -1;
                for (int y = height - 1; y >= 0; --y)
                {
                    min = ulong.MaxValue;

                    /// find location of min
                    for (int x = dx - 1; x <= dx + 1; ++x)
                    {
                        if (x < 0 || x > tmpWidth)
                            continue;

                        if (energy[x, y] < min)
                        {
                            min = energy[x, y];
                            minIndex = x;
                        }
                    }

                    if (min == ulong.MaxValue)
                        break;

                    dx = minIndex;
                    seam.PushBack(dx);
                }

                // if seam is ok, then add and try to found another (if needed)
                if (seam.IsOK)
                    founded_seams.AddSeam(seam);
            }

            return founded_seams;
        }