public SegmentedStrokes AboveAverageSegments()
        {
            bool performAverage = false;

            if (!performAverage)
            {
                return(this);
            }

            Hashtable scores      = new Hashtable();
            int       accumulator = 0;

            foreach (SegmentOffset offset in this.segments.Keys)
            {
                StrokeCollection strokeCol = (StrokeCollection)this.segments[offset];
                int segmentScore           = strokeCol.strokes.Count;

                accumulator += segmentScore;

                ArrayList list = null;
                if (scores.ContainsKey(segmentScore))
                {
                    list = (ArrayList)scores[segmentScore];
                }
                else
                {
                    list = new ArrayList();
                    scores[segmentScore] = list;
                }

                OffsetStrokesPair pair = new OffsetStrokesPair();
                pair.offset           = offset;
                pair.strokeCollection = strokeCol;
                list.Add(pair);
            }

            // Determine the average across all segments
            double average = 0.0;

            if (this.segments.Keys.Count > 0)
            {
                average = accumulator / this.segments.Keys.Count;
            }

            SegmentedStrokes result = new SegmentedStrokes(this.segWidth, this.segHeight, this.Width, this.Height);

            foreach (int score in scores.Keys)
            {
                if (score > (average / 2.0))
                {
                    ArrayList list = (ArrayList)scores[score];
                    foreach (OffsetStrokesPair pair in list)
                    {
                        result.AddSegment(pair.strokeCollection, pair.offset);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public Bitmap Compose()
        {
            Bitmap strokeBitmap = new Bitmap(Properties.Resources.brush1);

            int counter = 1;
            //int totalTasks = resizedImages.Count * 3 + 1;
            //StatusReporter.Instance.SetTotalTasks(totalTasks);
            int taskCounter = 1;

            DateTime start = DateTime.Now;

            SegmentedStrokes finalRegion = new SegmentedStrokes(10, 10, this.paintingBitmap.Width, this.paintingBitmap.Height);

            ArrayList strokes = null;

            foreach (Bitmap image in resizedImages)
            {
                MomentsBasedPainter painter = new MomentsBasedPainter(15, strokeBitmap);
                strokes = painter.GenerateStrokes(image);

                SegmentedStrokes segStrokes  = new SegmentedStrokes(10, 10, image.Width, image.Height, strokes);
                SegmentedStrokes interesting = segStrokes.AboveAverageSegments();

                //Bitmap results = interesting.GenerateBitmap();
                //ImageTools.GenWorkingImage(results);
                //image.Save("downloaded-" + counter + ".jpg");
                //results.Save("average-" + counter + ".jpg");
                counter++;

                finalRegion.AttemptIncorporation(interesting);
            }

            ArrayList finalStrokes = finalRegion.UnifyStrokes();

            finalStrokes.Sort();
            Console.WriteLine("Final total strokes: " + finalStrokes.Count);

            IPainter p     = new MomentsBasedPainter(15, strokeBitmap);
            Bitmap   final = p.Render(finalStrokes, this.paintingBitmap);

            //ImageTools.GenWorkingImage(final);

            TimeSpan duration = DateTime.Now - start;

            final.Save("composition.jpg");

            Console.WriteLine("Composition completed in " + duration.TotalMilliseconds + "ms");

            return(final);
        }
        public void Incorporate(SegmentedStrokes toBeIncorporated, SegmentOffset absoluteOffset)
        {
            int randX = this.rand.Next(1, this.Width / 6);
            int randY = this.rand.Next(1, this.Height / 6);

            Point strokeOffset = new Point(randX + (absoluteOffset.xOffset * this.segWidth), randY + (absoluteOffset.yOffset * this.segHeight));

            foreach (SegmentOffset relativeOffset in toBeIncorporated.segments.Keys)
            {
                SegmentOffset    windowOffset = new SegmentOffset(absoluteOffset.xOffset + relativeOffset.xOffset, absoluteOffset.yOffset + relativeOffset.yOffset);
                StrokeCollection segment      = (StrokeCollection)toBeIncorporated.segments[relativeOffset];
                segment.filled       = true;
                segment.strokeOffset = strokeOffset;

                AddSegment(segment, windowOffset);
            }
        }
        public bool AttemptIncorporation(SegmentedStrokes toBeIncorporated)
        {
            for (int y = 0; y < this.MaxYOffset; y++)
            {
                for (int x = 0; x < this.MaxXOffset; x++)
                {
                    SegmentOffset offset = new SegmentOffset(x, y);

                    if (toBeIncorporated.FitsInto(this, offset))
                    {
                        this.Incorporate(toBeIncorporated, offset);

                        //System.Console.WriteLine("Region fits at location: " + offset.xOffset * toBeIncorporated.segWidth + ", " + offset.yOffset * toBeIncorporated.segHeight);

                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool FitsInto(SegmentedStrokes destRegion, SegmentOffset destOffset)
        {
            // For every segment within this "source" region, check to see if
            // each can be placed in its relative location in the destRegion.
            foreach (SegmentOffset offset in this.segments.Keys)
            {
                SegmentOffset adjusted = new SegmentOffset(destOffset.xOffset + offset.xOffset, destOffset.yOffset + offset.yOffset);
                if (destRegion.segments.ContainsKey(adjusted))
                {
                    StrokeCollection segment = (StrokeCollection)destRegion.segments[adjusted];
                    if (segment.filled)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }