示例#1
0
        public static ImageRaster3D <bool> GetShell3D6C(ImageRaster3D <bool> source, bool border_is_shell = false)
        {
            ITopologyElement     topology = new TopologyElementRaster3D6Connectivity(source.Raster);
            ImageRaster3D <bool> target   = new ImageRaster3D <bool>(source.Raster);

            GetShellRBA(source, topology, target, border_is_shell);
            return(target);
        }
示例#2
0
        public void TestDefaultBuilderTrivial4(IMaxTreeBuilder <int> builder)
        {
            int[] data = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            IImageRaster3D <int> image    = new ImageRaster3D <int>(3, 3, 1, data, false);
            ITopologyElement     topology = new TopologyElementRaster3D6Connectivity(image.Raster);
            IMaxTree <int>       maxtree  = builder.BuildMaxTree(data, new ComparerNatural <int>(), topology, data.Length);

            maxtree.GetDisplayValues();
        }
示例#3
0
        public void TestTrivial0(IAlphaPartitionTreeBuilder <float, float> builder)
        {
            ImageRaster3D <float> image            = new ImageRaster3D <float>();
            ITopologyElementEdge  element_topology = new TopologyElementRaster3D6Connectivity(image.Raster).GetElementEdgeRasterTopology();
            IFunctionDissimilarity <float, float> edge_function = new FunctionDistanceAbsoluteDifference();
            IAlphaPartitionTree <float>           tree          = builder.BuildAlphaPartitionTree(element_topology, edge_function, image.GetElementValues(false));

            Assert.AreEqual(1, tree.GetRealElementsIndexesWithMaxAlfa(0, 0).Length);
            Assert.AreEqual(1, tree.GetFullElementsIndexesWithMaxAlfa(0, 0).Length);
        }
示例#4
0
        public void TestTrivial1(IAlphaPartitionTreeBuilder <float, float> builder)
        {
            ImageRaster3D <float> image            = new ImageRaster3D <float>(10, 10, 10);
            ITopologyElementEdge  element_topology = new TopologyElementRaster3D6Connectivity(image.Raster).GetElementEdgeRasterTopology();
            IFunctionDissimilarity <float, float> edge_function = new FunctionDistanceAbsoluteDifference();
            IAlphaPartitionTree <float>           tree          = builder.BuildAlphaPartitionTree(element_topology, edge_function, image.GetElementValues(false));

            Assert.AreEqual(1000, tree.GetRealElementsIndexesWithMaxAlfa(0, 0).Length);
            Assert.AreEqual(3700, tree.GetFullElementsIndexesWithMaxAlfa(0, 0).Length);


            ToolsIOSerialization.SerializeToFile(@"E:\Data\Dropbox\Dropbox\TestData\Tree.blb", tree);
        }
示例#5
0
        public void TestDefaultBuilderVeryBig(IMaxTreeBuilder <int> builder)
        {
            Random random = new Random(0);

            int[] data = new int[512 * 512 * 10];
            for (int index = 1; index < data.Length; index++)
            {
                data[index] = (int)(random.NextDouble() * 100.0);
            }
            IImageRaster3D <int> image    = new ImageRaster3D <int>(512, 512, 10, data, false);
            ITopologyElement     topology = new TopologyElementRaster3D6Connectivity(image.Raster);
            IMaxTree <int>       maxtree  = builder.BuildMaxTree(data, new ComparerNatural <int>(), topology, data.Length);
        }
示例#6
0
        public void TestTrival0()
        {
            IMaxTreeBuilder <float> builder_max = new MaxTreeBuilderSingleQueue <float>();
            IAlphaPartitionTreeBuilder <float, float> builder_alfa_partition = new   AlphaPartitionTreeBuilderMinTree <float, float>(new AlgebraRealFloat32(), builder_max);

            ImageRaster3D <float> image            = new ImageRaster3D <float>();
            ITopologyElementEdge  element_topology = new TopologyElementRaster3D6Connectivity(image.Raster).GetElementEdgeRasterTopology();
            IFunctionDissimilarity <float, float> edge_function = new FunctionDistanceAbsoluteDifference();
            IAlphaPartitionTree <float>           tree          = builder_alfa_partition.BuildAlphaPartitionTree(element_topology, edge_function, image.GetElementValues(false));

            float [] values_input = new float [] { 555 };
            FilterAlfaPartitionMean <float> filter = new FilterAlfaPartitionMean <float>(new AlgebraRealFloat32());

            float[] values_filtered = filter.Filter(tree, values_input, 0, 0);
            Assert.AreEqual(555, values_filtered[0]);
        }
示例#7
0
        public void TestSimple1(IAlphaPartitionTreeBuilder <float, float> builder)
        {
            ImageRaster3D <float> image            = new ImageRaster3D <float>(9, 1, 1, new float[] { 1, 2, 2, 3, 4, 2, 4, 4, 1 }, false);
            ITopologyElementEdge  element_topology = new TopologyElementRaster3D6Connectivity(image.Raster).GetElementEdgeRasterTopology();
            IFunctionDissimilarity <float, float> edge_function = new FunctionDistanceAbsoluteDifference();
            IAlphaPartitionTree <float>           tree          = builder.BuildAlphaPartitionTree(element_topology, edge_function, image.GetElementValues(false));

            Assert.AreEqual(1, tree.GetRealElementsIndexesWithMaxAlfa(0, 0.5f).Length);
            Assert.AreEqual(5, tree.GetRealElementsIndexesWithMaxAlfa(0, 1.5f).Length);
            Assert.AreEqual(8, tree.GetRealElementsIndexesWithMaxAlfa(0, 2.5f).Length);
            Assert.AreEqual(9, tree.GetRealElementsIndexesWithMaxAlfa(0, 3.5f).Length);

            Assert.AreEqual(2, tree.GetRealElementsIndexesWithMaxAlfa(6, 0.5f).Length);
            Assert.AreEqual(2, tree.GetRealElementsIndexesWithMaxAlfa(6, 1.5f).Length);
            Assert.AreEqual(8, tree.GetRealElementsIndexesWithMaxAlfa(6, 2.5f).Length);
            Assert.AreEqual(9, tree.GetRealElementsIndexesWithMaxAlfa(6, 3.5f).Length);
        }
示例#8
0
        public void TestSimple0()
        {
            IMaxTreeBuilder <float> builder_max = new MaxTreeBuilderSingleQueue <float>();
            IAlphaPartitionTreeBuilder <float, float> builder_alfa_partition = new AlphaPartitionTreeBuilderMinTree <float, float>(new AlgebraRealFloat32(), builder_max);


            float[] values_input                   = new float[] { 1, 2, 2, 3, 4, 2, 4, 4, 1 };
            ImageRaster3D <float> image            = new ImageRaster3D <float>(9, 1, 1, values_input, false);
            ITopologyElementEdge  element_topology = new TopologyElementRaster3D6Connectivity(image.Raster).GetElementEdgeRasterTopology();
            IFunctionDissimilarity <float, float> edge_function = new FunctionDistanceAbsoluteDifference();
            IAlphaPartitionTree <float>           tree          = builder_alfa_partition.BuildAlphaPartitionTree(element_topology, edge_function, image.GetElementValues(false));


            FilterAlfaPartitionMean <float> filter = new FilterAlfaPartitionMean <float>(new AlgebraRealFloat32());
            int max_size = 1000;

            float[] values_filtered05 = filter.Filter(tree, values_input, max_size, 0.5f);
            float[] values_filtered15 = filter.Filter(tree, values_input, max_size, 1.5f);
            float[] values_filtered25 = filter.Filter(tree, values_input, max_size, 2.5f);
        }
示例#9
0
        public static ImageRaster3D <bool> FilterComponents3D6(ImageRaster3D <bool> image, int minimal_size)
        {
            ITopologyElement topology = new TopologyElementRaster3D6Connectivity(image.Raster);

            bool[] result     = image.GetElementValues(true);
            bool[] to_do      = image.GetElementValues(true);
            int[]  neighbours = new int[topology.MaximumConnectivity];
            for (int element_index = 0; element_index < image.Raster.ElementCount; element_index++)
            {
                if (to_do[element_index])
                {
                    List <int>  connected_component_list = new List <int>();
                    Queue <int> fringe = new Queue <int>();
                    fringe.Enqueue(element_index);
                    to_do[element_index] = false;
                    connected_component_list.Add(element_index);

                    while (fringe.Count != 0)
                    {
                        int next_element = fringe.Dequeue();
                        topology.ElementNeighboursRBA(next_element, neighbours);
                        for (int neighbour_index = 0; neighbour_index < neighbours.Length; neighbour_index++)
                        {
                            if ((neighbours[neighbour_index] != -1) && (to_do[neighbours[neighbour_index]]))
                            {
                                fringe.Enqueue(neighbours[neighbour_index]);
                                to_do[neighbours[neighbour_index]] = false;
                                connected_component_list.Add(neighbours[neighbour_index]);
                            }
                        }
                    }

                    if (connected_component_list.Count < minimal_size)
                    {
                        result.SetValues(connected_component_list, false);
                    }
                }
            }
            return(new ImageRaster3D <bool>(image.Raster, result, false));
        }