Libraryless. Click here for Pure Java version (5820L/38K).
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); } }
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1029767 |
Snippet name: | AI_PixelFindabilityMap1 |
Eternal ID of this version: | #1029767/21 |
Text MD5: | 7050d09b91b9bd99586a90a8c610272d |
Transpilation MD5: | bd9f7c107ae1a7602611f09cb28865b4 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-09-12 03:28:01 |
Source code size: | 1925 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 226 / 539 |
Version history: | 20 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |