public string[] AnalyzePicture(ArtImage artImage)
        {
            string[] arrayOfEachColumnCellValue = new string[WorkingCellCount];

            //method that compares first metric
            Dictionary<string, double> firstMetricValues = testDimensionAspect(artImage);

            //method for second metric
            colorSAD.determineBitFrequency(artImage);
            Dictionary<string, double> secondMetricValues = testColor(artImage);

            //method for obtaining the mean column values
            Dictionary<string, double> averageColumnValues = getColumnAverages(firstMetricValues, secondMetricValues);

            //fills the string array for the fields
            int i = 0;
            foreach (string artistName in allArtists.Keys)
            {
                arrayOfEachColumnCellValue[i] = artistName;

                string temp1 = "" + firstMetricValues[artistName] + ".0000";
                arrayOfEachColumnCellValue[i + 5] = temp1.Substring(0, 6);

                string temp2 = "" + secondMetricValues[artistName] + ".0000";
                arrayOfEachColumnCellValue[i + 10] = temp2.Substring(0, 6);

                string temp4 = "" + averageColumnValues[artistName] + ".0000";
                arrayOfEachColumnCellValue[i + 15] = temp4.Substring(0, 6);
                i++;
            }

            arrayOfEachColumnCellValue = SortBySimilarity(arrayOfEachColumnCellValue);

            return arrayOfEachColumnCellValue;
        }
예제 #2
0
        public void SetTextBox(String[] results, ArtImage image)
        {
            InputImage = image;
            List<string> artistNames = new List<string>();
            double[] averageValues = new double[5];
            for (int i = 0; i < 5; i++)
            {
                averageValues[i] = Convert.ToDouble(results[(results.Length - 5) + i]);
            }
            artistNames.Add(results[4]);
            for (int i = 0; i < 4; i++)
            {
                if (averageValues[4] - averageValues[i] < 5)
                {
                    artistNames.Add(results[i]);
                }
            }
            string resultString;
            if (artistNames.Count > 1)
            {
                resultString = "The results are inconclusive. The artist could be ";
                for (int j = 0; j < artistNames.Count - 1; j++)
                {
                    resultString += artistNames[j] + ", ";
                }
                resultString += "or " + artistNames[artistNames.Count - 1];
            }
            else
            {
                resultString = "The Artist of this image is " + artistNames[0];
            }

            ArtistResultBox.Text = resultString;
        }
        //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);
                    }
                }
            }
        }
예제 #4
0
 private void button2_Click(object sender, RoutedEventArgs e)
 {
     if (ImagePreview.Source != null)
     {
         ArtImage artImage = new ArtImage((BitmapImage)ImagePreview.Source, fileName);
         string[] results = artdentifier.AnalyzePicture(artImage);
         ResultBox.Text = "";
         ArtistHeader.Text = "Artist Names";
         Column1Header.Text = "Dimensions";
         Column2Header.Text = "Colors";
         Column3Header.Text = "Average";
         for (int i = 0; i < results.Length; i++)
         {
             artistChanceValues[i / COUNT_OF_TOP_ARTISTS_SHOWN, i % (COUNT_OF_TOP_ARTISTS_SHOWN)] = results[i];
         }
         for (int j = 0; j < COUNT_OF_TOP_ARTISTS_SHOWN; j++)
         {
             for (int k = 0; k < METRICS_MESURED_ON; k++)
             {
                 resultGrid[k, j].Text = artistChanceValues[k, j];
             }
         }
         DetermineArtist(results, artImage);
     }
     else
     {
         ResultBox.Text = "You must submit an image";
     }
 }
예제 #5
0
 public void AutomaticBox(String[] results, ArtImage image)
 {
     InputImage = image;
     List<string> artistNames = new List<string>();
     double[] averageValues = new double[5];
     for (int i = 0; i < 5; i++)
     {
         averageValues[i] = Convert.ToDouble(results[(results.Length - 5) + i]);
     }
     artistNames.Add(results[4]);
     for (int i = 0; i < 4; i++)
     {
         if (averageValues[4] - averageValues[i] < 5)
         {
             artistNames.Add(results[i]);
         }
     }
     if (!(artistNames.Count > 1))
     {
         artDistinguisher.AddArtImage(artistNames[0], InputImage);
     }
 }
예제 #6
0
 public double getDimensionRatio(ArtImage artImage)
 {
     double widthHeightRatio = (double)artImage.Width / artImage.Height;
     return widthHeightRatio;
 }
 public double calculateAccuracy()
 {
     double accuracy = 0.0;
     int imageCount = 0;
     int correctGuesses = 0;
     string dir = @"c:\Users\Jeff\Documents\GitHub\Capstone\Documentation\Misc\Z_TestImages\";
     string[] filePaths = Directory.GetFiles(dir);
     foreach (string str in filePaths)
     {
         if (isAnImageType(str))
         {
             Uri artistLocation = new Uri(str);
             try
             {
                 BitmapImage myBitmapImage = BitmapImageFromURI.GetBitmapImage(artistLocation);
                 ArtImage ai = new ArtImage(myBitmapImage, str);
                 Console.WriteLine(ai.KnownArtistName);
                 string[] results = AnalyzePicture(ai);
                 string[,] artistChanceValues = new string[4, 5];
                 for (int i = 0; i < results.Length; i++)
                 {
                     artistChanceValues[i / 5, i % 5] = results[i];
                 }
                 if (ai.KnownArtistName.Contains(artistChanceValues[0, 4]))
                 {
                     correctGuesses++;
                 }
                 imageCount++;
             }
             catch (Exception e)
             {
                 Console.WriteLine("error with " + str);
             }
         }
     }
     accuracy = ((double)correctGuesses) / ((double)imageCount);
     return accuracy;
 }
 public void AddArtImage(string artistName, ArtImage artImage)
 {
     allArtists[artistName].Add(artImage);
 }
        private Dictionary<string, double> testDimensionAspect(ArtImage artImage)
        {
            Dictionary<string, double> DimensionalCheckRatios = new Dictionary<string, double>();
            double dimensionalRatio = dimensionAnalyzer.getDimensionRatio(artImage);

            foreach (List<ArtImage> lists in allArtists.Values)
            {
                double dimensionalSimilarity = 0.00;
                int i = 1;
                foreach (ArtImage a in lists)
                {
                    double currentImageRatio = dimensionAnalyzer.getDimensionRatio(a);
                    double tempSimilarity = 1 - Math.Abs(dimensionalRatio - currentImageRatio);
                    if (tempSimilarity == 1)
                    {
                        dimensionalSimilarity = 1;
                        break;
                    }
                    else
                    {
                        if (tempSimilarity - (dimensionalSimilarity / i) > -20)
                        {
                            dimensionalSimilarity = dimensionalSimilarity + tempSimilarity;
                            i++;
                        }
                    }

                }
                foreach (KeyValuePair<String, List<ArtImage>> kvp in allArtists)
                {
                    if (kvp.Value.Equals(lists))
                    {
                        dimensionalSimilarity = dimensionalSimilarity == 1 ? 1 : (dimensionalSimilarity / i);
                        DimensionalCheckRatios.Add(kvp.Key, dimensionalSimilarity * 100);
                    }
                }
            }
            return DimensionalCheckRatios;
        }
예제 #10
0
        private Dictionary<string, double> testColor(ArtImage artImage)
        {
            Dictionary<string, double> ColorResultReturns = new Dictionary<string, double>();

            Dictionary<string, double> redColorResults = compareImageRed(artImage);
            Dictionary<string, double> greenColorResults = compareImageGreen(artImage);
            Dictionary<string, double> blueColorResults = compareImageBlue(artImage);

            foreach (string artistName in allArtists.Keys)
            {
                double meanColorValues = (redColorResults[artistName] + greenColorResults[artistName]
                    + blueColorResults[artistName]) / 3;
                ColorResultReturns.Add(artistName, meanColorValues);
            }

            return ColorResultReturns;
        }
예제 #11
0
 private Dictionary<string, double> compareImageRed(ArtImage artImage)
 {
     Dictionary<string, double> redCheckRatios = new Dictionary<string, double>();
     byte inputRed = artImage.getMostFrequentRed();
     foreach (List<ArtImage> lists in allArtists.Values)
     {
         double redSimilarity = 0.00;
         int i = 1;
         foreach (ArtImage a in lists)
         {
             byte redValue = a.getMostFrequentRed();
             double redRatio = ((double)Math.Abs(redValue - inputRed)) / 255;
             double tempSimilarity = 1 - redRatio;
             if (tempSimilarity == 1)
             {
                 redSimilarity = 1;
                 break;
             }
             else
             {
                 redSimilarity = redSimilarity + tempSimilarity;
                 i++;
             }
         }
         foreach (KeyValuePair<String, List<ArtImage>> kvp in allArtists)
         {
             if (kvp.Value.Equals(lists))
             {
                 redSimilarity = redSimilarity == 1 ? 1 : (redSimilarity / i);
                 redCheckRatios.Add(kvp.Key, redSimilarity * 100);
             }
         }
     }
     return redCheckRatios;
 }
예제 #12
0
        private void DetermineArtist(String[] results, ArtImage image)
        {
            if ((bool)CheckBox1.IsChecked)
            {
                ResultWindow resultWindow = new ResultWindow(artdentifier);
                resultWindow.SetTextBox(results, image);
                resultWindow.ShowDialog();
            }
            else if ((bool)CheckBox2.IsChecked)
            {

            }
        }