public Collage(string templateImageLocation, string imagesLocation, ImageSize scale = ImageSize.Medium, CollageSize collageSize = CollageSize.Medium)
        {
            ImageSize   = scale;
            CollageSize = collageSize;
            Image i = ImageFileIO.ImageFromFile(templateImageLocation);

            //Template = new CollageTemplateImage(i, templateScale);
            Template = new CollageTemplateImage(i, ImageSize, CollageSize);

            string[] fileNames = ImageFileIO.GetAllImagesFromFolder(imagesLocation);
            ImagePaths = fileNames.ToArray();
            //Image[] images = new Image[fileNames.Count()];

            //for (int j = 0; j < fileNames.Count(); ++j)
            //{
            //    images[j] = ImageFileIO.ImageFromFile(fileNames.ElementAt(j));
            //}

            CollageImages = new CollageImage[fileNames.Count()];
            Console.WriteLine("Calculating average image values...");
            for (int j = 0; j < fileNames.Count(); ++j)
            {
                //CollageImage ci = new CollageImage(images[j], Image_Scale);
                CollageImage ci = new CollageImage(fileNames[j], (int)ImageSize);
                CollageImages[j] = ci;
                Console.WriteLine("avg value: " + ci.ColorValues.AvgRGB + "   Count = " + j);
            }
            Console.WriteLine("Done with image values");
            Array.Sort(CollageImages);
        }
Beispiel #2
0
    public void SetImageFromTexture2D(Texture2D tex2d)
    {
        int            collageSize    = _Collage.gameBoard.collageSize;
        Texture2D      scaledTex      = CollageImage.ScaleTexture(tex2d, collageSize, collageSize);
        SpriteRenderer spriteRenderer = this.GetComponent <SpriteRenderer>();

        spriteRenderer.sprite = Sprite.Create(scaledTex, new Rect(0, 0, collageSize, collageSize), new Vector2(0.5f, 0.5f));
    }
        private static void test1()
        {
            Image i = ImageFileIO.ImageFromFile(@"C:\Users\chance\Documents\Visual Studio 2015\Capstone\HollisC_Collage\SimpleCollage\SimpleCollage\images\needle.jpg");
            //CollageTemplateImage c = new CollageTemplateImage(i);
            //c.GenerateTemplateValues();
            //c.printValues();

            CollageImage ci = new CollageImage(i);
            //Console.WriteLine("Average rgb: " + ci.AvgRGB);
        }
Beispiel #4
0
    IEnumerator DelayStart()
    {
        yield return(new WaitForSeconds(1f));

        //Debug.Log("DDDDDDDEBUG");
        //For debug use
        Texture2D debugTex = _Collage.currentLevelInfo.GetSketch();

        SetImageFromTexture2D(CollageImage.ScaleTexture(debugTex, _Collage.gameBoard.collageSize, _Collage.gameBoard.collageSize));
        yield return(null);
    }
        /// <summary>
        /// Gets the closest image using averageRbg from a given list of CollageImages
        /// </summary>
        /// <param name="templateValue"></param>
        /// <param name="cImages"></param>
        /// <returns></returns>
        private CollageImage GetClosestImage(double templateValue, IEnumerable <CollageImage> cImages)
        {
            CollageImage closest = null;
            double       range   = 255;

            for (int j = 0; j < cImages.Count(); ++j)
            {
                double next = Math.Abs(cImages.ElementAt(j).ColorValues.AvgRGB - templateValue);
                if (next < range)
                {
                    range   = next;
                    closest = CollageImages[j];
                }
            }
            return(closest);
        }
        public void GenerateCollage()
        {
            Random rand      = new Random(DateTime.Now.Millisecond);
            var    uriSource = new Uri(@"desert.jpg", UriKind.Relative);

            for (int i = 0; i < 10; i++)
            {
                CollageImage img = new CollageImage();
                img.Left   = (0.2 + rand.NextDouble()) % 0.8;
                img.Top    = (0.2 + rand.NextDouble()) % 0.8;
                img.Width  = 100 + rand.NextDouble() * 100;
                img.Height = 100 + rand.NextDouble() * 100;
                img.Image  = "desert.jpg";
                img.Angle  = rand.NextDouble() * 360;
                Images.Add(img);
            }
        }
Beispiel #7
0
 private void RemoveImageFromPanel(CollageImage control)
 {
     try
     {
         foreach (var view in this.views)
         {
             if (view.ImageCanvas.Children.Contains(control))
             {
                 view.ImageCanvas.Children.Remove(control);
                 control.Dispose();
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         this.controller.HandleError(ex);
     }
 }
        private CollageImage GetClosestImage(ColorValue templateValue)
        {
            CollageImage closest       = null;
            double       range         = int.MaxValue;
            ColorName    dominant      = templateValue.GetDominantColor();
            double       dominantValue = templateValue.GetDominantValue();

            for (int j = 0; j < CollageImages.Count(); ++j)
            {
                //double next = Math.Abs(CollageImages[j].ColorValues.GetColorValue(dominant) - dominantValue);
                double next = ColorDistance(CollageImages[j].ColorValues, templateValue);
                if (next < range)
                {
                    range   = next;
                    closest = CollageImages[j];
                }
            }
            return(closest);
        }
Beispiel #9
0
    public Texture2D GetSketch()
    {
        //Debug.Log("here" + collageFractionInfoList.Count + " " + levelTexture.height + " " + levelTexture.width);
        Texture2D sketch = new Texture2D(levelTexture.width, levelTexture.height, levelTexture.format, true);

        foreach (CollageFractionInfo collage in collageFractionInfoList)
        {
            int nextIndex  = childrenLevelCollageIndexes.IndexOf(collage.collageId);
            int positionId = collage.positionId;
            if (positionId != -1)
            {
                //Debug.Log("here has some ids");
                int       xOffset = positionId % gameBoard.gridCountPerLine;
                int       yOffset = positionId / gameBoard.gridCountPerLine;
                Texture2D tex     = collage.currentTexture2d;
                //Debug.Log("collage texture2d: " + tex.width + " " + tex.height);
                if (nextIndex != -1)
                {
                    LevelCollageInfo childLevel = childrenLevelInfo[nextIndex];
                    if (!childLevel.visited)
                    {
                        tex = CollageImage.ScaleTexture(PlayerInfo.questionTexture, tex.width, tex.height);
                    }
                    else
                    {
                        tex = CollageImage.ScaleTexture(childLevel.GetSketch(), tex.width, tex.height);
                    }
                }
                //send picture to sketches

                for (int i = 0; i < tex.width; i++)
                {
                    for (int j = 0; j < tex.height; j++)
                    {
                        Color color = tex.GetPixel(i, j);
                        sketch.SetPixel(xOffset * levelCollageSize + i, yOffset * levelCollageSize + j, color);
                    }
                }
            }
        }
        sketch.Apply();
        return(sketch);
    }
Beispiel #10
0
        private void test2()
        {
            // read in images
            IEnumerable <string> fileNames = Directory.EnumerateFiles(@"C:\Users\chance\Documents\Visual Studio 2015\Capstone\HollisC_Collage\SimpleCollage\SimpleCollage\images");

            Image[] images = new Image[fileNames.Count()];
            for (int j = 0; j < fileNames.Count(); ++j)
            {
                images[j] = ImageFileIO.ImageFromFile(fileNames.ElementAt(j));
            }

            List <CollageImage> cImgs = new List <CollageImage>();

            for (int j = 0; j < images.Count(); ++j)
            {
                CollageImage c = new CollageImage(images[j]);
                cImgs.Add(c);
                //Console.WriteLine(c.AvgRGB);
            }
        }
Beispiel #11
0
        private void DisplayImageTimerTick(object sender, EventArgs e)
        {
            try
            {
                string       path    = this.photoRepository.GetNextPhotoFilePath();
                ICollageView view    = this.GetNextDisplayView();
                var          control = new CollageImage(path, this);
                view.ImageCanvas.Children.Add(control);
                this.imageQueue.Enqueue(control);

                if (this.imageQueue.Count > this.Configuration.NumberOfPhotos)
                {
                    this.RemoveImageFromQueue();
                }

                this.SetUserControlPosition(control, view);
            }
            catch (Exception ex)
            {
                this.controller.HandleError(ex);
                this.controller.Shutdown();
            }
        }
Beispiel #12
0
        /// <summary>
        /// This method will take the list of images and the template image and create a 2d array of CollageImages, the collage, using gray scale
        /// </summary>
        public void GenerateCollageLayout(bool useColor)
        {
            Console.WriteLine("Generating Collage...");
            CollageLayout = new CollageImage[Template.TemplateValues.GetLength(0), Template.TemplateValues.GetLength(1)];

            for (int row = 0; row < Template.TemplateImage.Height; ++row)
            {
                for (int col = 0; col < Template.TemplateImage.Width; ++col)
                {
                    if (useColor)
                    {
                        ColorValue   value   = Template.TemplateValues[row, col];
                        CollageImage closest = GetClosestImage(value);
                        CollageLayout[row, col] = closest;
                    }
                    else
                    {
                        double       value   = Template.TemplateValues[row, col].AvgRGB;
                        CollageImage closest = GetClosestImage(value);
                        CollageLayout[row, col] = closest;
                    }
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Gets the closest image using average rbg and the entire collageImages array
        /// </summary>
        /// <param name="templateValue"></param>
        /// <returns></returns>
        private CollageImage GetClosestImage(double templateValue)
        {
            CollageImage closest = GetClosestImage(templateValue, CollageImages);

            return(closest);
        }