public ElementType[] Filter(IAlphaPartitionTree <ElementType> tree, ElementType [] values, int max_size, ElementType max_alpha) { ElementType[] filtered = new ElementType[tree.RealElementCount]; bool[] done = new bool [tree.RealElementCount]; for (int element_index = 0; element_index < tree.RealElementCount; element_index++) { if (!done[element_index]) { int [] element_group = tree.GetRealElementsIndexesWithMaxAlfaMaxSize(element_index, max_size, max_alpha); ElementType mean = this.algebra.AddIdentity; foreach (int group_element_index in element_group) { mean = this.algebra.Add(mean, values[group_element_index]); done[group_element_index] = true; } mean = this.algebra.Divide(mean, this.algebra.ToDomain((float)element_group.Length)); foreach (int group_element_index in element_group) { filtered[group_element_index] = mean; done[group_element_index] = true; } } } return(filtered); }
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); }
public AlphaPartitionTree3D( IAlphaPartitionTreeBuilder <ElementValueType, EdgeValueType> builder, ITopologyElementEdgeRaster <IRaster3DInteger> topology, IFunctionDissimilarity <ElementValueType, EdgeValueType> edge_function, IImageRaster <IRaster3DInteger, ElementValueType> image) { //TODO make sure topology matches image ElementValueType[] element_values = image.GetElementValues(false); tree = builder.BuildAlphaPartitionTree(topology, edge_function, element_values); }
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); }
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]); }
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); }
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); }