Ejemplo n.º 1
0
        /// <summary>
        /// Classifies each pixel in <paramref name="image"/> and stores the results in <paramref name="dist"/>.
        /// </summary>
        /// <param name="tree">The tree used for the computation</param>
        /// <param name="image">Image to classify</param>
        /// <param name="dist">Image which is used to store the distributions</param>
        public static void ClassifySoft <T>(this DecisionTree <ImageDataPoint <T>, T[]> tree, IMultichannelImage <T> image, DistributionImage dist)
        {
            int rows    = image.Rows;
            int columns = image.Columns;
            List <ImageDataPoint <T> > points = new List <ImageDataPoint <T> >();
            List <int> indices = new List <int>();
            int        i       = 0;

            for (short r = 0; r < rows; r++)
            {
                for (short c = 0; c < columns; c++, i++)
                {
                    points.Add(new ImageDataPoint <T>(image, r, c, -1));
                    indices.Add(i);
                }
            }
            INodeInfo <ImageDataPoint <T>, T[]>[] info = new INodeInfo <ImageDataPoint <T>, T[]> [points.Count];
            DecisionTree <ImageDataPoint <T>, T[]> .assignLabels(tree._root, points, info, indices);

            i = 0;
            for (short r = 0; r < rows; r++)
            {
                for (short c = 0; c < columns; c++, i++)
                {
                    dist.Add(r, c, info[i].Distribution);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Classifies points from <paramref name="labeledImage"/> (using the mask if present) and adds the distributions at each pixel to <paramref name="dist"/>.
        /// </summary>
        /// <param name="tree">The tree used for the computation</param>
        /// <param name="labeledImage">The image to classify</param>
        /// <param name="dist">Image which is used to store the distributions</param>
        public static void ClassifySoft <T>(this DecisionTree <ImageDataPoint <T>, T[]> tree, LabeledImage <T> labeledImage, DistributionImage dist)
        {
            List <ImageDataPoint <T> > points = labeledImage.CreateAllDataPoints(BackgroundSampleMode.Full);
            List <int> indices = new List <int>();

            for (int i = 0; i < points.Count; i++)
            {
                indices.Add(i);
            }
            INodeInfo <ImageDataPoint <T>, T[]>[] info = new INodeInfo <ImageDataPoint <T>, T[]> [points.Count];
            DecisionTree <ImageDataPoint <T>, T[]> .assignLabels(tree._root, points, info, indices);

            for (int i = 0; i < info.Length; i++)
            {
                dist.Add(points[i].Row, points[i].Column, info[i].Distribution);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Computes a label distribution at each pixel by combining its node distributions.
        /// </summary>
        /// <returns>Distribution image</returns>
        public DistributionImage ComputeDistributionImage()
        {
            DistributionImage dist = new DistributionImage(_rows, _columns, _data[0, 0, 0].Distribution.Length);

            dist.ID = ID;
            for (int r = 0; r < _rows; r++)
            {
                for (int c = 0; c < _columns; c++)
                {
                    for (int t = 0; t < _trees; t++)
                    {
                        dist.Add(r, c, _data[r, c, t].Distribution);
                    }
                }
            }
            dist.DivideThrough(_trees);
            dist.Normalize();
            return(dist);
        }