sclass AI_PixelFindabilityMap1 { int trials = 16; double gain = 1; BufferedImage inputImage; BWImage scaledInputImage; int inputWidth = 128; int coreW = 8, coreH = coreW; int outerW = 16, outerH = outerW; int leewayX, leewayY; double[] heatMap; run { scaledInputImage = BWImage(scaleToWidth(inputWidth, inputImage)); leewayX = scaledInputImage.getWidth()-coreW; leewayY = scaledInputImage.getHeight()-coreH; //heatMap = BWImage(leewayX, leewayY); heatMap = new double[leewayX*leewayY]; for y to leewayY: for x to leewayX: calcPixel(x, y); } void calcPixel(int x, int y) { Rect full = imageRect(scaledInputImage); Rect core = rect(x, y, coreW, coreH); Pt center = centerOfRect(core); //print(+core); BWImage bwCore = bwClip(scaledInputImage, core); double sum = 0; repeat trials { Rect outer = randomRect_enclosing_in(outerW, outerH, core, full); IBWImage bwClip = clipIBWImage(scaledInputImage, outer); Pt solution = Pt(center.x-outer.x, center.y-outer.y); //print("Solution: " + solution); Pt guess = translatePt(coreW/2, coreH/2, bwSpiralSearch(bwCore, bwClip)); //print("Guessed: " + guess); if (guess == null) guess = Pt(outerW/2, outerH/2); sum += ptSquaredDistance(solution, guess); } heatMap[y*leewayX+x] = sum; } BWImage heatMapImage() { //double max = doubleMax(heatMap); double max = (outerW-coreW)*(outerH-coreH)/gain*trials; BWImage img = new(leewayX, leewayY); int i = 0; for y to leewayY: for x to leewayX: img.setPixel(x, y, /*1f-*/(float) doubleRatio(heatMap[i++], max)); ret img; } BufferedImage mixedWithHeatMap() { ret combineBWImagesToColor(scaledInputImage, Color.red, bwBlackBorder(coreW/2.0, coreH/2.0, heatMapImage()), Color.green); } }