/// <summary> /// Computes a tree histogram for a sub-rectangle of the source image defined by the parameters. /// </summary> /// <param name="startRow">Starting row of the sub-rectangle</param> /// <param name="startColumn">Starting column of the sub-rectangle</param> /// <param name="rows">Number of rows in the sub-rectangle</param> /// <param name="columns">Number of columns in the sub-rectangle</param> /// <returns>A tree histogram</returns> public TreeHistogram ComputeHistogram(int startRow, int startColumn, int rows, int columns) { Dictionary <int, TreeNode>[] counts = new Dictionary <int, TreeNode> [_trees]; for (int i = 0; i < counts.Length; i++) { counts[i] = new Dictionary <int, TreeNode>(); } int[] maxIndex = new int[counts.Length]; for (int r = 0, srcR = startRow; r < rows; r++, srcR++) { for (int c = 0, srcC = startColumn; c < columns; c++, srcC++) { for (byte t = 0; t < _trees; t++) { INodeInfo <ImageDataPoint <T>, T[]> info = _data[srcR, srcC, t]; int index = info.TreeIndex; if (!counts[t].ContainsKey(index)) { counts[t][index] = new TreeNode(t, 0, info.LeafNodeIndex, info.TreeIndex); maxIndex[t] = Math.Max(maxIndex[t], index); } counts[t][index].Value++; } } } List <TreeNode> histogram = new List <TreeNode>(); for (byte t = 0; t < _trees; t++) { fill(t, 1, histogram, counts[t], maxIndex[t]); } return(TreeHistogram.Divide(new TreeHistogram(histogram), rows * columns)); }
/// <summary> /// Computes a histogram for all trees from the provided points. /// </summary> /// <param name="points">Points to classify</param> /// <returns>The histogram</returns> public TreeHistogram ComputeHistogram(List <T> points) { TreeHistogram histogram = _trees[0].ComputeHistogram(points); for (int t = 1; t < _numTrees; t++) { histogram = TreeHistogram.Union(histogram, _trees[t].ComputeHistogram(points)); } return(TreeHistogram.Divide(histogram, points.Count)); }