static double pixelSetRectangleness_factor = 5; static double pixelSetRectangleness(PixelSet set) { ret (pixelSetRectangleness_dimension(pixelSetBoundsByLine(set)) + pixelSetRectangleness_dimension(pixelSetBoundsByColumn(set)))/2; } static double pixelSetRectangleness_dimension(L l) { int[] a = intRangeStarts(l), b = intRangeEnds(l); double avgL = doubleAverage(a), avgR = doubleAverage(b); double width = avgR-avgL; double dev = standardDeviation(b)+standardDeviation(a); print("width=" + width + ", dev=" + dev); ret max(0, 1-dev*pixelSetRectangleness_factor/width); }