Example #1
0
        /// <summary>
        /// Classifies <paramref name="image"/>, creating a distribution over all labels at each pixel.
        /// </summary>
        /// <param name="tree">The tree used for the computation</param>
        /// <param name="image">Image to classify</param>
        /// <returns>Distributions at each pixel</returns>
        public static DistributionImage ClassifySoft <T>(this DecisionTree <ImageDataPoint <T>, T[]> tree, IMultichannelImage <T> image)
        {
            DistributionImage dist = new DistributionImage(image.Rows, image.Columns, tree.LabelCount);

            tree.ClassifySoft(image, dist);
            dist.Normalize();
            return(dist);
        }
Example #2
0
        /// <summary>
        /// Classifies every pixel in the provided image, returning a full distribution over all labels.
        /// </summary>
        /// <param name="forest">The forest used for the computation</param>
        /// <param name="image">Image to classify</param>
        /// <returns>The classified image</returns>
        public static DistributionImage ClassifySoft <T>(this DecisionForest <ImageDataPoint <T>, T[]> forest, LabeledImage <T> image)
        {
            DistributionImage dist = new DistributionImage(image.Image.Rows, image.Image.Columns, forest.LabelCount);

            dist.ID = image.ID;
            for (int t = 0; t < forest.TreeCount; t++)
            {
                forest[t].ClassifySoft(image, dist);
            }
            dist.DivideThrough(forest.TreeCount);
            dist.Normalize();
            return(dist);
        }
Example #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);
        }
Example #4
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);
                }
            }
        }
Example #5
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);
            }
        }