public void EstimateSpaceSize() { Intarray labels = new Intarray(); labels.Copy(segmentation); ImgLabels.label_components(ref labels); Narray <Rect> boxes = new Narray <Rect>(); ImgLabels.bounding_boxes(ref boxes, labels); Floatarray distances = new Floatarray(); distances.Resize(boxes.Length()); distances.Fill(99999f); for (int i = 1; i < boxes.Length(); i++) { Rect b = boxes[i]; for (int j = 1; j < boxes.Length(); j++) { Rect n = boxes[j]; int delta = n.x0 - b.x1; if (delta < 0) { continue; } if (delta >= distances[i]) { continue; } distances[i] = delta; } } float interchar = NarrayUtil.Fractile(distances, PGetf("space_fractile")); space_threshold = interchar * PGetf("space_multiplier"); // impose some reasonable upper and lower bounds float xheight = 10.0f; // FIXME space_threshold = Math.Max(space_threshold, PGetf("space_min") * xheight); space_threshold = Math.Min(space_threshold, PGetf("space_max") * xheight); }