private static IList <double> DiffFusionImages(FusionTestDataContainer data, string testName)
        {
            var outputPath = new DirectoryInfo(Path.Combine(typeof(FusionLayerCoregistrationTests).FullName, testName));

            if (outputPath.Exists)
            {
                outputPath.Delete(true);
            }
            outputPath.Create();

            using (var log = File.CreateText(Path.Combine(outputPath.FullName, "data.csv")))
            {
                // if the overlay image is not rendered at all, this coregistration test would pass, but then the color compositing test would fail
                using (var referenceDisplaySet = data.CreateBaseDisplaySet())
                {
                    using (var testDisplaySet = data.CreateFusionDisplaySet())
                    {
                        var list  = new List <double>();
                        int index = 0;
                        foreach (var testImage in testDisplaySet.PresentationImages)
                        {
                            var referenceImage = referenceDisplaySet.PresentationImages[index];
                            NormalizePresentationImageDisplay(testImage);
                            NormalizePresentationImageDisplay(referenceImage);

                            Bitmap diff;
                            double result = ImageDiff.Compare(ImageDiffAlgorithm.Euclidian, referenceImage, testImage, out diff);
                            diff.Save(Path.Combine(outputPath.FullName, string.Format("diff{0:000}.png", index)));
                            diff.Dispose();
                            log.WriteLine("{0}, {1:f6}", index, result);
                            list.Add(result);

                            ++index;
                        }

                        return(list);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static IList <double> DiffFusionOperatorResults(IColorMap colorMap, bool thresholding, string testName)
        {
            var outputPath = new DirectoryInfo(Path.Combine(typeof(FusionColorCompositingTest).FullName, testName));

            if (outputPath.Exists)
            {
                outputPath.Delete(true);
            }
            outputPath.Create();

            // this kind of test requires that the base and overlay slices be unsigned and precisely coincident
            using (var data = new FusionTestDataContainer(
                       () => TestDataFunction.GradientX.CreateSops(false, Modality.CT, new Vector3D(1.0f, 1.0f, 15.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit),
                       () => TestDataFunction.GradientY.CreateSops(false, Modality.PT, new Vector3D(1.0f, 1.0f, 15.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit)))
            {
                using (var log = File.CreateText(Path.Combine(outputPath.FullName, "data.csv")))
                {
                    log.WriteLine("{0}, {1}, {2}, {3}", "n", "opacity", "alpha", "diff");
                    using (var baseDisplaySet = data.CreateBaseDisplaySet())
                    {
                        using (var overlayDisplaySet = data.CreateOverlayDisplaySet())
                        {
                            using (var fusionDisplaySet = data.CreateFusionDisplaySet())
                            {
                                var list = new List <double>();

                                var imageIndex  = fusionDisplaySet.PresentationImages.Count / 2;
                                var fusionImage = fusionDisplaySet.PresentationImages[imageIndex];

                                for (int n = 0; n <= 10; n++)
                                {
                                    var opacity = n / 10f;

                                    SetFusionDisplayParameters(fusionImage, colorMap, opacity, thresholding);
                                    using (IPresentationImage referenceImage =
                                               Fuse(baseDisplaySet.PresentationImages[imageIndex], overlayDisplaySet.PresentationImages[imageIndex], colorMap, opacity, thresholding))
                                    {
                                        using (var referenceBmp = DrawToBitmap(referenceImage))
                                        {
                                            referenceBmp.Save(Path.Combine(outputPath.FullName, string.Format("reference{0}.png", n)));
                                        }

                                        using (var fusionBmp = DrawToBitmap(fusionImage))
                                        {
                                            fusionBmp.Save(Path.Combine(outputPath.FullName, string.Format("test{0}.png", n)));
                                        }

                                        // because the fusion display set is generated from real base images and *reformatted* overlay images,
                                        // there will necessarily be higher differences at the edges of the useful image area

                                        Bitmap diff;
                                        double result = ImageDiff.Compare(ImageDiffAlgorithm.Euclidian, referenceImage, fusionImage, new Rectangle(18, 18, 98, 98), out diff);
                                        diff.Save(Path.Combine(outputPath.FullName, string.Format("diff{0}.png", n)));
                                        diff.Dispose();
                                        log.WriteLine("{0}, {1:f2}, {2}, {3:f6}", n, opacity, (int)(255 * opacity), result);
                                        list.Add(result);
                                    }
                                }

                                return(list);
                            }
                        }
                    }
                }
            }
        }