//checks every pixel in an artImage, and counts each time a specific color occurs
        public void determineBitFrequency(ArtImage artImage)
        {
            BitmapImage bitmap = artImage.getBitmapImage();
            byte[] pixels = ConvertBitmapImageToByteArray(bitmap);
            int stride = bitmap.PixelWidth * 4;
            int currentR = 0;
            int currentG = 0;
            int currentB = 0;
            int currentA = 0;
            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    int index = (y * stride) + (4 * x);
                    if (index < pixels.Length)
                    {
                        currentR = roundNumber(pixels[index]) > 250 ? 255 : roundNumber(pixels[index]);
                        currentG = roundNumber(pixels[index + 1]) > 250 ? 255 : roundNumber(pixels[index + 1]);
                        currentB = roundNumber(pixels[index + 2]) > 250 ? 255 : roundNumber(pixels[index + 2]);
                        currentA = roundNumber(pixels[index + 3]) > 250 ? 255 : roundNumber(pixels[index + 3]);

                        Color currentColor = Color.FromArgb((byte)currentA, (byte)currentR, (byte)currentG, (byte)currentB);
                        artImage.countColor(currentColor);
                    }
                }
            }
        }
 private void button3_Click(object sender, RoutedEventArgs e)
 {
     ArtImage artImage = new ArtImage((BitmapImage)ImagePreview.Source, fileName);
     string clusterName = clusterer.AnalyzePicture(artImage);
     ClusterPopUp clusterPopUp = new ClusterPopUp();
     clusterPopUp.SetTextBox(clusterName);
     clusterPopUp.ShowDialog();
     SubmitButton.Visibility = Visibility.Hidden;
 }
Beispiel #3
0
 public string AnalyzePicture(ArtImage artImage)
 {
     string clusterName = "";
     double bestDistance = 10000;
     for (int i = 1; i <= CLUSTER_COUNT; i++)
     {
         string clusterNum = "cluster" + i;
         IClusterableItem ici = getAverageClusterPointFromArtImageList(clusters[clusterNum]);
         double currentDistance = getDistance(ici, artImage);
         if (currentDistance <= bestDistance)
         {
             bestDistance = currentDistance;
             clusterName = "Cluster " + i;
         }
     }
     return clusterName;
 }