Exemple #1
0
        internal static void FillLeafImage <T>(this DecisionTree <ImageDataPoint <T>, T[]> tree, LeafImage <T> leafImage, IMultichannelImage <T> image)
        {
            INodeInfo <ImageDataPoint <T>, T[]>[, ,] array = leafImage.RawArray;
            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;
            int treeLabel = tree.TreeLabel;

            for (short r = 0; r < rows; r++)
            {
                for (short c = 0; c < columns; c++, i++)
                {
                    array[r, c, treeLabel] = info[i];
                }
            }
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        /// <summary>
        /// Get the node information for all points from all trees.
        /// </summary>
        /// <typeparam name="T">The type of the data point</typeparam>
        /// <typeparam name="D">The underlying feature type of the data point</typeparam>
        /// <param name="forest">The forest to query</param>
        /// <param name="points">The points to get info for</param>
        /// <returns>The desired info</returns>
        public static INodeInfo <T, D>[][] GetNodeInfo <T, D>(this DecisionForest <T, D> forest, List <T> points) where T : IDataPoint <D>
        {
            List <Task <INodeInfo <T, D>[]> > tasks   = new List <Task <INodeInfo <T, D>[]> >();
            TaskFactory <INodeInfo <T, D>[]>  factory = new TaskFactory <INodeInfo <T, D>[]>();

            for (int t = 0; t < forest.TreeCount; t++)
            {
                tasks.Add(factory.StartNew(arg =>
                {
                    DecisionTree <T, D> tree = (DecisionTree <T, D>)arg;
                    INodeInfo <T, D>[] info  = new INodeInfo <T, D> [points.Count];
                    DecisionTree <T, D> .assignLabels(tree._root, points, info, Enumerable.Range(0, points.Count).ToList());
                    return(info);
                }, forest[t]));
            }
            Task.WaitAll(tasks.ToArray());
            return(tasks.Select(o => o.Result).ToArray());
        }