示例#1
0
        /// <summary>
        /// Classifies each pixel in the image and returns the leaf nodes which they end up in.
        /// </summary>
        /// <param name="forest">The forest used for the computation</param>
        /// <param name="image">Image to classify</param>
        /// <returns>A leaf image</returns>
        public static LeafImage <T> ComputeLeafImage <T>(this DecisionForest <ImageDataPoint <T>, T[]> forest, IMultichannelImage <T> image)
        {
            LeafImage <T> leafImage = new LeafImage <T>(image.Rows, image.Columns, forest.TreeCount);

            leafImage.ID = image.ID;
            for (int i = 0; i < forest.TreeCount; i++)
            {
                forest[i].FillLeafImage(leafImage, image);
            }
            return(leafImage);
        }
示例#2
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];
                }
            }
        }