Exemple #1
0
        public override Tuple <IImageRaster <IRaster2DInteger, int>, IImageRaster <IRaster2DInteger, float>, IList <int[]>, IList <float[]> > Initialize(IRaster2DInteger raster)
        {
            IImageRaster2D <int>   region_image               = new ImageRaster2D <int>(raster);
            IImageRaster2D <float> distance_image             = new ImageRaster2D <float>(raster, Single.MaxValue);
            Tuple <IList <int[]>, IList <float[]> > Centroids = InitializeCentroids(raster);
            IList <int[]>   cluster_spatial_centroids         = Centroids.Item1;
            IList <float[]> cluster_feature_centroids         = Centroids.Item2;

            int[] neigbourhood_dimensions    = d_cluster_dimensions_double;
            int   neigbourhood_element_count = ((neigbourhood_dimensions[0] * 2) + 1) * ((neigbourhood_dimensions[1] * 2) + 1);

            int[] element_index_indexes = new int[neigbourhood_element_count];

            for (int centroid_index = 0; centroid_index < cluster_spatial_centroids.Count; centroid_index++)
            {
                raster.GetNeigbourhoodElementIndexesRBA(cluster_spatial_centroids[centroid_index], neigbourhood_dimensions, element_index_indexes);
                for (int element_index_index = 0; element_index_index < neigbourhood_element_count; element_index_index++)
                {
                    int element_index = element_index_indexes[element_index_index];
                    if (element_index != -1)
                    {
                        int[] element_coordinates = raster.GetElementCoordinates(element_index);
                        float distance            = FunctionDistanceEuclidean.ComputeStatic(element_coordinates, cluster_spatial_centroids[centroid_index]);
                        if (distance < distance_image.GetElementValue(element_index))
                        {
                            distance_image.SetElementValue(element_index, distance);
                            region_image.SetElementValue(element_index, centroid_index);
                        }
                    }
                }
            }
            return(new Tuple <IImageRaster <IRaster2DInteger, int>, IImageRaster <IRaster2DInteger, float>, IList <int[]>, IList <float[]> >(region_image, distance_image, cluster_spatial_centroids, cluster_feature_centroids));
        }
        public static void DistanceTransform2DOosterbroekRBA(ImageRaster2D <bool> mask_image, float[] voxel_size, ImageRaster2D <float> distance_image)
        {
            ImageRaster3D <bool>  mask_image_3d     = new ImageRaster3D <bool>(mask_image.Raster.Size0, mask_image.Raster.Size1, 1, mask_image.GetElementValues(false), false);
            ImageRaster3D <float> distance_image_3d = new ImageRaster3D <float>(mask_image.Raster.Size0, mask_image.Raster.Size1, 1, distance_image.GetElementValues(false), false);

            DistanceTransform3DOosterbroekRBA(mask_image_3d, voxel_size, distance_image_3d);
        }
Exemple #3
0
 public void TestDefaultBuilderTrivial0(IMaxTreeBuilder <int> builder)
 {
     int[] data = new int[] { 0, 0, 0, 0 };
     IImageRaster2D <int> image    = new ImageRaster2D <int>(2, 2, data, false);
     ITopologyElement     topology = new TopologyElementRaster2D4Connectivity(image.Raster);
     IMaxTree <int>       maxtree  = builder.BuildMaxTree(data, new ComparerNatural <int>(), topology, data.Length);
 }
Exemple #4
0
        public static ImageRaster2D <bool> GetShell2D8C(ImageRaster2D <bool> source, bool border_is_shell = false)
        {
            ITopologyElement     topology = new TopologyElementRaster2D8Connectivity(source.Raster);
            ImageRaster2D <bool> target   = new ImageRaster2D <bool>(source.Raster);

            GetShellRBA(source, topology, target, border_is_shell);
            return(target);
        }
    private ImageRaster2D <Color> IntializeOutputImage(IImageRaster2D <Color> input_image, int output_width,
                                                       int output_height)
    {
        ImageRaster2D <Color> output_image = new ImageRaster2D <Color>(output_width, output_height);
        Random random = new Random();

        /* randomize the last few columns from the input image */
        for (int element_index = 0; element_index < output_image.Raster.ElementCount; element_index++)
        {
            int random_x = random.Next((input_image.Raster.Size0 - 1) - (scale * 2)) + scale;
            int random_y = random.Next((input_image.Raster.Size1 - 1) - (scale * 2)) + scale;
            output_image.SetElementValue(element_index, input_image.GetElementValue(random_x, random_y));
        }
        return(output_image);
    }
Exemple #6
0
        public SpectralAnaliser(ModelApplication application, int channel, int block_size, int block_stride, int size_x, int size_y)
        {
            this.application = application;
            this.Dispatcher  = Dispatcher.CurrentDispatcher;
            this.blocker     = new Blocker(block_size, 8);
            this.blocker.ExecuteStart();
            this.is_running = false;

            this.channel = channel;

            this.image   = new ImageRaster2D <float>(size_x, size_y);
            this.x_index = 0;
            this.f_rate  = block_size / (size_y * 2);

            Render();
        }
Exemple #7
0
        public void TestDefaultBuilderTrivial3(IMaxTreeBuilder <int> builder)
        {
            int[] data = new int[] { 1, 2, 2, 0, 2, 1 };
            IImageRaster2D <int> image    = new ImageRaster2D <int>(2, 3, data, false);
            ITopologyElement     topology = new TopologyElementRaster2D4Connectivity(image.Raster);
            IMaxTree <int>       maxtree  = builder.BuildMaxTree(data, new ComparerNatural <int>(), topology, data.Length);

            int[] element_indexes_0 = maxtree.GetFullElementsIndexesOfElementLevelAndAbove(1);
            Assert.AreEqual(1, element_indexes_0.Length);
            int[] element_indexes_1 = maxtree.GetFullElementsIndexesOfElementLevelAndAbove(4);
            Assert.AreEqual(2, element_indexes_1.Length);
            int[] element_indexes_2 = maxtree.GetFullElementsIndexesOfElementLevelAndAbove(0);
            Assert.AreEqual(5, element_indexes_2.Length);
            int[] element_indexes_3 = maxtree.GetFullElementsIndexesOfElementLevelAndAbove(3);
            Assert.AreEqual(6, element_indexes_3.Length);
        }
        public IImageRaster <IRaster2DInteger, bool> Render(Tuple <List <int>, IRaster3DInteger> render_source)
        {
            List <int>       elements_true = render_source.Item1;
            IRaster3DInteger source_raster = render_source.Item2;

            float[,] coordinates_image   = new float[elements_true.Count, 3];
            float[,] elements_projection = new float[elements_true.Count, 3];
            int [] coordinates = new int [3];

            for (int element_index_index = 0; element_index_index < elements_true.Count; element_index_index++)
            {
                source_raster.GetElementCoordinatesRBA(elements_true[element_index_index], coordinates);
                coordinates_image[element_index_index, 0] = coordinates[0];
                coordinates_image[element_index_index, 1] = coordinates[1];
                coordinates_image[element_index_index, 2] = coordinates[2];
            }

            for (int element_index = 0; element_index < elements_true.Count; element_index++)
            {
                elements_projection[element_index, 0] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_x[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_x[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_x[2]);

                elements_projection[element_index, 1] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_y[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_y[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_y[2]);

                elements_projection[element_index, 2] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_z[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_z[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_z[2]);
            }

            Raster2DInteger      bitmap_raster     = new Raster2DInteger(bitmap_size_x, bitmap_size_y);
            ImageRaster2D <bool> destination_image = new ImageRaster2D <bool>(bitmap_size_x, bitmap_size_y);

            for (int element_index = 0; element_index < elements_true.Count; element_index++)
            {
                int x_target = (int)elements_projection[element_index, 0] + (bitmap_raster.Size0 / 2);
                int y_target = (int)elements_projection[element_index, 1] + (bitmap_raster.Size1 / 2);

                if (bitmap_raster.ContainsCoordinates(x_target, y_target))
                {
                    destination_image.SetElementValue(x_target, y_target, true);
                }
            }
            return(destination_image);
        }
Exemple #9
0
        public void TestDefaultBuilderBig(IMaxTreeBuilder <int> builder)
        {
            Random random = new Random(0);

            int[] data = new int [512 * 512];
            for (int index = 1; index < data.Length; index++)
            {
                data[index] = (int)(random.NextDouble() * 100.0);
            }
            IImageRaster2D <int> image    = new ImageRaster2D <int>(512, 512, data, false);
            ITopologyElement     topology = new TopologyElementRaster2D4Connectivity(image.Raster);
            IMaxTree <int>       maxtree  = builder.BuildMaxTree(data, new ComparerNatural <int>(), topology, data.Length);

            maxtree.GetFullElementsIndexesOfElementLevelAndAbove(0);
            maxtree.GetFullElementsIndexesOfElementLevelAndAbove(500);
            maxtree.GetFullElementsIndexesOfElementLevelAndAbove(1800);
        }
    public ImageRaster2D <Color> GenerateTexture(IImageRaster2D <Color> input_image, int output_width, int output_height)
    {
        ImageRaster2D <Color> output_image = IntializeOutputImage(input_image, output_width, output_height);
        Random random = new Random();

        Tuple <Color, Color[]>[] input_neighborhoods = BuildInputNeighborhoods(input_image);

        for (int iteration_index = 0; iteration_index < this.iterations; iteration_index++)
        {
            //get random index
            int random_x = random.Next((output_width - 1) - (scale * 2)) + scale;
            int random_y = random.Next((output_height - 1) - (scale * 2)) + scale;
            //finde
            SetBestMatchPixel(input_neighborhoods, output_image, random_x, random_y);
        }

        return(output_image);
    }
Exemple #11
0
        public IImageRaster2D <float> Render(IImageSpace <float, float> source_image)
        {
            IImageRaster2D <float> destination_image = new ImageRaster2D <float>();

            float[] coordinates = new float [render_origen.Length];
            for (int index_y = 0; index_y < this.resolution_y; index_y++)
            {
                for (int index_x = 0; index_x < this.resolution_x; index_x++)
                {
                    ToolsCollection.CopyRBA(this.render_origen, coordinates);
                    for (int index_dimension = 0; index_dimension < this.dimension_count; index_dimension++)
                    {
                        coordinates[index_dimension] += (render_stride_x[index_dimension] * index_x) + (render_stride_y[index_dimension] * index_y);
                    }
                    destination_image.SetElementValue(index_x, index_y, source_image.GetLocationValue(coordinates));
                }
            }
            return(destination_image);
        }
        public void TestDistance2DOosterbroek()
        {
            ImageRaster2D <bool> mask = new ImageRaster2D <bool>(5, 5);

            mask[0]  = true;
            mask[6]  = true;
            mask[12] = true;
            mask[13] = true;
            mask[19] = true;
            ImageRaster2D <float> distance = new ImageRaster2D <float>(mask.Raster);

            ToolsDistance.DistanceTransform2DOosterbroekRBA(mask, new float[] { 1.0f, 1.0f, 1.0f }, distance);
            Assert.AreEqual(0.0f, distance[0]);
            Assert.AreEqual(1.0f, distance[1]);
            Assert.AreEqual(ToolsMath.Sqrt(2.0f), distance[2]);
            Assert.AreEqual(2.0f, distance[3]);
            Assert.AreEqual(ToolsMath.Sqrt(5.0f), distance[4]);
            Assert.AreEqual(ToolsMath.Sqrt(8.0f), distance[20]);
        }
        public static void DistanceTransform2DSlowRBA(ImageRaster2D <bool> mask_image, float[] voxel_size, ImageRaster2D <float> distance_image)
        {
            IRaster2DInteger raster = mask_image.Raster;
            int size_0 = mask_image.Raster.Size0;
            int size_1 = mask_image.Raster.Size1;

            // Apply the transform in the x-direction
            //for (int plane_index = 0; plane_index < size_z * size_y; plane_index++)
            //{
            Parallel.For(0, size_0, index_0 =>
            {
                for (int index_1 = 0; index_1 < size_1; index_1++)
                {
                    float best_distance = float.MaxValue;
                    if (mask_image.GetElementValue(index_0, index_1))
                    {
                        best_distance = 0;
                    }
                    else
                    {
                        for (int index_0_1 = 0; index_0_1 < size_0; index_0_1++)
                        {
                            for (int index_1_1 = 0; index_1_1 < size_1; index_1_1++)
                            {
                                if (mask_image.GetElementValue(index_0_1, index_1_1))
                                {
                                    float distance = ToolsMath.Sqrt(ToolsMath.Sqr((index_0_1 - index_0) * voxel_size[0]) + ToolsMath.Sqr((index_1_1 - index_1) * voxel_size[0]));
                                    if (distance < best_distance)
                                    {
                                        best_distance = distance;
                                    }
                                }
                            }
                        }
                    }
                    distance_image.SetElementValue(index_0, index_1, best_distance);
                }
            });
        }
Exemple #14
0
 public static ImageRaster2D <bool> Threshold <DomainType>(ImageRaster2D <DomainType> image, DomainType threshold)
     where DomainType : IComparable <DomainType>
 {
     return(new ImageRaster2D <bool>(image.Raster, image.Convert <bool>(new FunctionStep <DomainType>(threshold)).GetElementValues(false), false));
 }
        public static WriteableBitmap ConvertImageRaster2DToWriteableBitmap <RangeType>(ImageRaster2D <RangeType> image_raster_base, IFunction <RangeType, int> converter)
        {
            int width  = image_raster_base.Raster.Size0;
            int height = image_raster_base.Raster.Size1;

            System.Windows.Media.PixelFormat format = System.Windows.Media.PixelFormats.Bgr24;

            WriteableBitmap result = new WriteableBitmap(width, height, 96, 96, System.Windows.Media.PixelFormats.Bgr24, null);

            int[] pixels = ToolsMathFunction.Convert(image_raster_base.GetElementValues(false), converter);
            int   stride = (format.BitsPerPixel / 8) * width;
            int   bytes  = stride * height;

            //TODO convert
            result.Lock();
            result.WritePixels(new Int32Rect(0, 0, width, height), pixels, bytes, stride);
            result.Unlock();
            return(result);
        }