/// <summary>
        /// Only for debug / evaluation use.
        /// </summary>
        /// <param name="fixedMask"></param>
        /// <param name="movingMask"></param>
        private void CalculateMetrics(sitk.Image fixedMask, sitk.Image movingMask)
        {
            if (fixedMask != null && movingMask != null)
            {
                sitk.LabelOverlapMeasuresImageFilter overlapFilter = VisualizationEvaluationUtils.GetOverlapImageFilter(fixedMask, movingMask);

                if (overlapFilter != null)
                {
                    double diceCoef      = overlapFilter.GetDiceCoefficient();
                    double falseNegative = overlapFilter.GetFalseNegativeError();
                    double falsePositive = overlapFilter.GetFalsePositiveError();
                    double jaccard       = overlapFilter.GetJaccardCoefficient();
                    double meanOverlap   = overlapFilter.GetMeanOverlap();
                    double unionOverlap  = overlapFilter.GetUnionOverlap();

                    string dice   = diceCoef.ToString("0.##");
                    string jacc   = jaccard.ToString("0.##");
                    string negPos = string.Format("{0} / {1}", falseNegative.ToString("0.##"), falsePositive.ToString("0.##"));

                    Console.WriteLine("### Metrics ###");
                    Console.WriteLine("Dice: " + dice);
                    Console.WriteLine("Jaccard: " + jacc);
                    Console.WriteLine("False negative / false positive: " + negPos);
                }
            }
        }
        private void buttonCalcCoef_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            string fixedImageFilename  = registrationParameters.FixedImageFilename;
            string movingImageFilename = comboBoxMovingImage.SelectedValue.ToString();
            bool   isInnerSeg          = comboBoxSegmentationParams.SelectedIndex == 1;

            // read images
            Image <Bgr, byte> img01 = ReadWriteUtils.ReadOpenCVImageFromFile <Bgr, byte>(fixedImageFilename);
            Image <Bgr, byte> img02 = ReadWriteUtils.ReadOpenCVImageFromFile <Bgr, byte>(movingImageFilename);

            // whole particle seg
            Image <Gray, byte> mask01w;
            string             mask01wFn = DoWholeTissueSegmentation(img01, out mask01w, "\\mask01w.png");

            Image <Gray, byte> mask02w;
            string             mask02wFn = DoWholeTissueSegmentation(img02, out mask02w, "\\mask02w.png");

            sitk.LabelOverlapMeasuresImageFilter overlapFilter = null;
            if (isInnerSeg)
            {
                string mask01iFn = DoInnerTissueSegmentation(img01, mask01w, "\\mask01i.png");
                string mask02iFn = DoInnerTissueSegmentation(img02, mask02w, "\\mask02i.png");

                overlapFilter = GetOverlapImageFilter(mask01iFn, mask02iFn);

                DeleteFile(mask01iFn);
                DeleteFile(mask02iFn);
            }
            else
            {
                overlapFilter = GetOverlapImageFilter(mask01wFn, mask02wFn);
            }

            if (overlapFilter != null)
            {
                double diceCoef      = overlapFilter.GetDiceCoefficient();
                double falseNegative = overlapFilter.GetFalseNegativeError();
                double falsePositive = overlapFilter.GetFalsePositiveError();
                double jaccard       = overlapFilter.GetJaccardCoefficient();
                double meanOverlap   = overlapFilter.GetMeanOverlap();
                double unionOverlap  = overlapFilter.GetUnionOverlap();

                labelDice.Text         = diceCoef.ToString("0.###");
                labelJacc.Text         = jaccard.ToString("0.###");
                labelfalseNegPos.Text  = string.Format("{0} / {1}", falseNegative.ToString("0.###"), falsePositive.ToString("0.###"));
                labelMeanOverlap.Text  = meanOverlap.ToString("0.###");
                labelUnionOverlap.Text = unionOverlap.ToString("0.###");
            }

            DeleteFile(mask01wFn);
            DeleteFile(mask02wFn);

            Cursor.Current = Cursors.Default;
        }
 /// <summary>
 /// Get an overlap measure image filter for given masks.
 /// </summary>
 /// <param name="mask01">mask</param>
 /// <param name="mask02">corresponding mask</param>
 /// <returns>overlap meassure filter</returns>
 public static sitk.LabelOverlapMeasuresImageFilter GetOverlapImageFilter(sitk.Image mask01, sitk.Image mask02)
 {
     sitk.LabelOverlapMeasuresImageFilter overlapFilter = new sitk.LabelOverlapMeasuresImageFilter();
     overlapFilter.Execute(mask01, mask02);
     return(overlapFilter);
 }