public void ReadTileColours(IMakerClient client, ProjectResponse project)
        {
            // At the moment is takes into account the four quadrant averages of the file
            // rather than just one average which represents the whole tile.
            // Convert the ARGB values stored in project into Color objects
            var tiles        = client.ReadAllImageFiles(project.Project.SmallFileIds);
            var tilesColours = tiles.Files.Select(x => Color.FromArgb(x.Data.AverageWhole)).ToList();

            // Find the closest standard Color object for each color in tile files colours
            var tilesClosestColours         = new FileColourModel().FindClosestColour(tilesColours);
            var tilesFilesClosestColoursHex = tilesClosestColours.Select(x => x.ToHex()).ToList();

            var tilesDictionary = ConvertColourListToDictionary(tilesFilesClosestColoursHex);

            TileImageColorDictionary = tilesDictionary;
            JsonTileImageColours     = JsonConvert.SerializeObject(tilesDictionary, Formatting.Indented);
            JsonTileImageHexColours  = JsonConvert.SerializeObject(tilesDictionary.Keys, Formatting.Indented);
        }
示例#2
0
        public ImageMosaicResponse Generate(IMakerClient client, string id, bool random = false, int tileWidth = 10, int tileHeight = 10, bool colourBlended = false,
                                            bool enhanced = false, int enhancedThreshold = 50, bool edgeDetection = false, int threshold = 110)
        {
            // Get project
            var project = ProjectErrorCheck(client, id);

            if (!String.IsNullOrEmpty(project.Error))
            {
                return(new ImageMosaicResponse()
                {
                    Error = project.Error
                });
            }

            if (enhanced && edgeDetection)
            {
                return(new ImageMosaicResponse()
                {
                    Error = "Enhance and edge detection are mutually exclusive"
                });
            }

            //  Get all imagefileindexstructure files for the id
            var tileFilesId = project.Project.SmallFileIds.ToList();
            var tileFiles   = client.ReadAllImageFiles(tileFilesId);

            //  Get the image file index structure for the master image
            var masterFileId = project.Project.LargeFileId;
            var masterFile   = client.ReadImageFile(masterFileId);

            if (!String.IsNullOrEmpty(tileFiles.Error) || !String.IsNullOrEmpty(masterFile.Error))
            {
                return(new ImageMosaicResponse()
                {
                    Error = "Master or tile images cannot be read"
                });
            }

            if (enhanced && !EnhancedThresholdErrorCheck(enhancedThreshold))
            {
                return(new ImageMosaicResponse()
                {
                    Error = "Threshold must be in valid range"
                });
            }

            var edges = new List <PixelCoordinates>();

            // Get the edge coordinates if option set
            if (edgeDetection)
            {
                if (!ThresholdErrorCheck(threshold))
                {
                    return(new ImageMosaicResponse()
                    {
                        Error = "Threshold must be in valid range"
                    });
                }
                edges = client.GetEdgeCoordinates(id, masterFile.File, threshold).Edges.ToList();
            }

            return(client.Generate(id, tileFiles.Files, masterFile.File, random, tileWidth, tileHeight, colourBlended, enhanced, enhancedThreshold, edgeDetection, edges));
        }