Esempio n. 1
0
        public void TestMorphologicalErosionRBA()
        {
            ImageRaster3D <float> source = new ImageRaster3D <float>(5, 5, 5);
            ImageRaster3D <float> target = new ImageRaster3D <float>(5, 5, 5);

            source.SetElementValue(2, 2, 2, 1);
            List <int[]> offsets = new List <int[]>();

            offsets.Add(new int[] { 0, 0, 0 });
            StructuringElement3D structure_0 = new StructuringElement3D(offsets);

            ToolsImageRaster.MorphologicalErosionRBA(source, structure_0, 0, target);
            Assert.AreEqual(1, target.GetElementIndexesWithValue(1).Count);
            offsets.Add(new int[] { 1, 0, 0 });
            offsets.Add(new int[] { -1, 0, 0 });
            offsets.Add(new int[] { 0, 1, 0 });
            offsets.Add(new int[] { 0, -1, 0 });
            offsets.Add(new int[] { 0, 0, 1 });
            offsets.Add(new int[] { 0, 0, -1 });
            StructuringElement3D structure_1 = new StructuringElement3D(offsets);

            ToolsImageRaster.MorphologicalErosionRBA(source, structure_1, 0, target);
            Assert.AreEqual(0, target.GetElementIndexesWithValue(1).Count);
            source.SetElementValue(1, 2, 2, 1);
            source.SetElementValue(3, 2, 2, 1);
            source.SetElementValue(2, 1, 2, 1);
            source.SetElementValue(2, 3, 2, 1);
            source.SetElementValue(2, 2, 1, 1);
            source.SetElementValue(2, 2, 3, 1);
            ToolsImageRaster.MorphologicalErosionRBA(source, structure_1, 0, target);
            Assert.AreEqual(1, target.GetElementIndexesWithValue(1).Count);
        }
Esempio n. 2
0
        public static ImageRaster3D <RangeType> MorphologicalOpening <RangeType>(ImageRaster3D <RangeType> source, StructuringElement3D structure, RangeType default_value)
            where RangeType : IComparable <RangeType>
        {
            ImageRaster3D <RangeType> temp   = new ImageRaster3D <RangeType>(source.Raster);
            ImageRaster3D <RangeType> target = new ImageRaster3D <RangeType>(source.Raster);

            MorphologicalOpeningRBA(source, structure, default_value, temp, target);
            return(target);
        }
Esempio n. 3
0
        public static void MorphologicalDilationRBA <RangeType>(ImageRaster3D <RangeType> source, StructuringElement3D structure, RangeType default_value, ImageRaster3D <RangeType> target)
            where RangeType : IComparable <RangeType>
        {
            if (!source.Raster.Equals(target.Raster))
            {
                throw new Exception("Raster Mismatch");
            }
            IRaster3DInteger raster = source.Raster;

            //Parallel.For(0, source.ElementCount, source_element_index =>
            for (int source_element_index = 0; source_element_index < source.ElementCount; source_element_index++)
            {
                int[]     coordinates = raster.GetElementCoordinates(source_element_index);
                RangeType value       = default_value;
                bool      found       = false;
                for (int offset_index = 0; offset_index < structure.FlippedOffsets.Count; offset_index++)
                {
                    int[] offset = structure.FlippedOffsets[offset_index];
                    if (raster.ContainsCoordinates(coordinates[0] + offset[0], coordinates[1] + offset[1], coordinates[2] + offset[2]))
                    {
                        if (found)
                        {
                            value = ToolsMath.Max(value, source.GetElementValue(coordinates[0] + offset[0], coordinates[1] + offset[1], coordinates[2] + offset[2]));
                        }
                        else
                        {
                            value = source.GetElementValue(coordinates[0] + offset[0], coordinates[1] + offset[1], coordinates[2] + offset[2]);
                            found = true;
                        }
                    }
                }
                target.SetElementValue(source_element_index, value);
            }//);
        }
Esempio n. 4
0
        //TODO speed up
        public static void MorphologicalOpeningRBA <RangeType>(ImageRaster3D <RangeType> source, StructuringElement3D structure, RangeType default_value, ImageRaster3D <RangeType> temp, ImageRaster3D <RangeType> target)
            where RangeType : IComparable <RangeType>
        {
            if ((!source.Raster.Equals(temp.Raster)) || (!source.Raster.Equals(target.Raster)))
            {
                throw new Exception("Raster Mismatch");
            }
            IRaster3DInteger raster = source.Raster;

            //Do erosion
            MorphologicalErosionRBA(source, structure, default_value, temp);

            //Do dilation
            MorphologicalDilationRBA(temp, structure, default_value, target);
        }