コード例 #1
0
        public async Task RunAsync(IColorSpace colorSpace, int clusters, string outputDirectory, bool saveColorHistogram)
        {
            IsComplete = false;
            IsRunning  = true;
            var clusterOperation = new BitmapClusterOperation("batch", colorSpace, "_converted");
            await clusterOperation.RunAsync(OriginalImage.ToStandardRgbBitmap(), clusters, Path.GetFileNameWithoutExtension(OriginalFilePath), false);

            outputFileName = GetOutputFileName(OriginalFilePath, outputDirectory, colorSpace, clusters, ".png");
            clusterOperation.Bitmap.Save(outputFileName);

            if (saveColorHistogram)
            {
                string histogramOutputDirectory = Path.Combine(outputDirectory, "colorHistograms");
                Directory.CreateDirectory(histogramOutputDirectory);
                SaveWeightedColorsToJson(clusterOperation, histogramOutputDirectory, colorSpace, clusters);
            }

            ComputedImage = clusterOperation.Bitmap;
            ColorWeights  = clusterOperation.ColorWeights;
            Colors        = clusterOperation.Colors;
            IsRunning     = false;
            IsComplete    = true;
        }
コード例 #2
0
        private async Task ComputeSingle()
        {
            int clusters;

            if (!int.TryParse(ClusterCountSingle.Text, out clusters))
            {
                MessageBox.Show("Could not parse the cluster count");
                return;
            }
            if (clusters < 1 || clusters > 100)
            {
                MessageBox.Show("Clusters must be between 1 and 100");
                return;
            }

            StandardRgbBitmap sourceBitmap = sourceImage.ToStandardRgbBitmap();

            Func <Task>[] tasks =
            {
                () => rgbOperation.RunAsync(sourceBitmap,    clusters, originalFileName, ShowSteps.IsChecked == true),
                () => cieLuvOperation.RunAsync(sourceBitmap, clusters, originalFileName, ShowSteps.IsChecked == true),
                () => cieLabOperation.RunAsync(sourceBitmap, clusters, originalFileName, ShowSteps.IsChecked == true)
            };

            if (ParallelExecution.IsChecked == true)
            {
                await Task.WhenAll(tasks.Select(t => t()));
            }
            else
            {
                foreach (var t in tasks)
                {
                    await t();
                }
            }
        }