Exemplo n.º 1
0
        public static void EvaluateRectObjects(string gt_dir, string auto_dir)
        {
            int gt_count_total = 0, auto_count_total = 0, matched_count_total = 0;

            string[] gt_xml_files = Directory.GetFiles(gt_dir, "*.xml");
            using (StreamWriter sw = new StreamWriter("Evaluation.txt"))
            {
                sw.WriteLine("FigureName\tGT Panels\tAuto Panels\tMatched Panels");
                for (int i = 0; i < gt_xml_files.Length; i++)
                {
                    string gt_xml_file   = gt_xml_files[i];
                    string auto_xml_file = Path.Combine(auto_dir, Path.GetFileName(gt_xml_file).Replace("_data.xml", ".xml"));
                    if (!File.Exists(auto_xml_file))
                    {
                        continue;
                    }

                    iPhotoDrawAnnotation        gt_annotation   = new iPhotoDrawAnnotation(); gt_annotation.LoadRectObjects(gt_xml_file);
                    PanelSegmentationAnnotation auto_annotation = new PanelSegmentationAnnotation(); auto_annotation.LoadRectObjects(auto_xml_file);

                    int gt_count, auto_count, matched_count;
                    ObjectAnnotation.EvaluateRectObjects(gt_annotation, auto_annotation, out gt_count, out auto_count, out matched_count);
                    sw.WriteLine("{0}\t{1}\t{2}\t{3}", gt_annotation.figureFilename, gt_count, auto_count, matched_count);

                    gt_count_total      += gt_count;
                    auto_count_total    += auto_count;
                    matched_count_total += matched_count;
                }

                double recall    = (double)matched_count_total / (double)gt_count_total;
                double precision = (double)matched_count_total / (double)auto_count_total;
                double fscore    = 2 * precision * recall / (precision + recall);

                sw.WriteLine("Total\t{0}\t{1}\t{2}", gt_count_total, auto_count_total, matched_count_total);
                sw.WriteLine("Precision is {0}", precision);
                sw.WriteLine("Recall is {0}", recall);
                sw.WriteLine("FScore is {0}", fscore);
            }
        }
Exemplo n.º 2
0
        private static void EvaluateRectObjects(ObjectAnnotation gt_annotation, ObjectAnnotation auto_annotation, out int gt_count, out int auto_count, out int matched_count)
        {
            RectObject[] gt_rect_objs   = gt_annotation.rectObjects.ToArray();
            RectObject[] auto_rect_objs = auto_annotation.rectObjects.ToArray();

            gt_count = 0;  bool[] auto_matched = new bool[auto_rect_objs.Length];

            for (int i = 0; i < gt_rect_objs.Length; i++)
            {
                RectObject gt_rect_obj = gt_rect_objs[i];
                if (!gt_rect_obj.Name.ToLower().Trim().StartsWith("panel"))
                {
                    continue;                                                         //We are not evaluating labels yet.
                }
                gt_count++;

                //Search auto annotation to find matches
                for (int j = 0; j < auto_rect_objs.Length; j++)
                {
                    RectObject auto_rect_obj = auto_rect_objs[j];

                    {//Criteria 1: Rectangle overlapping is larger than 75%
                        Rectangle overlapping_rect = Rectangle.Intersect(gt_rect_obj.Rect, auto_rect_obj.Rect);
                        double    overlapping_area = overlapping_rect.Width * overlapping_rect.Height;
                        double    gt_area          = gt_rect_obj.Rect.Width * gt_rect_obj.Rect.Height;
                        if (overlapping_area / gt_area < 0.75)
                        {
                            continue;
                        }
                    }

                    {//Criteria 2: Overlapping to adjacent panle of the matching reference panel is less than 5%
                        int k; for (k = 0; k < gt_rect_objs.Length; k++)
                        {
                            if (k == i)
                            {
                                continue;
                            }

                            RectObject gt_rect_obj1 = gt_rect_objs[k];
                            if (!gt_rect_obj1.Name.ToLower().Trim().StartsWith("panel"))
                            {
                                continue;                                                          //We are not evaluating labels yet.
                            }
                            Rectangle overlapping_rect = Rectangle.Intersect(gt_rect_obj1.Rect, auto_rect_obj.Rect);
                            double    overlapping_area = overlapping_rect.Width * overlapping_rect.Height;
                            double    gt_area          = gt_rect_obj1.Rect.Width * gt_rect_obj1.Rect.Height;
                            if (overlapping_area / gt_area > 0.05)
                            {
                                break;
                            }
                        }
                        if (k != gt_rect_objs.Length)
                        {
                            continue;                           //This means auto_rect_obj overlaps with an adjacent gt_rect_obj and larger than 5%.
                        }
                    }

                    auto_matched[j] = true; break;
                }
            }

            //Compute Precision and Recall
            auto_count    = auto_rect_objs.Length;
            matched_count = 0; for (int i = 0; i < auto_matched.Length; i++)
            {
                if (auto_matched[i])
                {
                    matched_count++;
                }
            }
        }