Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

57
LINES

< > BotCompany Repo | #1029767 // AI_PixelFindabilityMap1

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5820L/38K).

1  
sclass AI_PixelFindabilityMap1 {
2  
  int trials = 16;
3  
  double gain = 1;
4  
  BufferedImage inputImage;
5  
  BWImage scaledInputImage;
6  
  int inputWidth = 128;
7  
  int coreW = 8, coreH = coreW;
8  
  int outerW = 16, outerH = outerW;
9  
  int leewayX, leewayY;
10  
  double[] heatMap;
11  
12  
  run {
13  
    scaledInputImage = BWImage(scaleToWidth(inputWidth, inputImage));
14  
    leewayX = scaledInputImage.getWidth()-coreW;
15  
    leewayY = scaledInputImage.getHeight()-coreH;
16  
    //heatMap = BWImage(leewayX, leewayY);
17  
    heatMap = new double[leewayX*leewayY];
18  
    for y to leewayY:
19  
      for x to leewayX:
20  
        calcPixel(x, y);
21  
  }
22  
  
23  
  void calcPixel(int x, int y) {
24  
    Rect full = imageRect(scaledInputImage);
25  
    Rect core = rect(x, y, coreW, coreH);
26  
    Pt center = centerOfRect(core);
27  
    //print(+core);
28  
    BWImage bwCore = bwClip(scaledInputImage, core);
29  
    double sum = 0;
30  
    repeat trials {
31  
      Rect outer = randomRect_enclosing_in(outerW, outerH, core, full);
32  
      IBWImage bwClip = clipIBWImage(scaledInputImage, outer);
33  
      Pt solution = Pt(center.x-outer.x, center.y-outer.y);
34  
      //print("Solution: " + solution);
35  
      Pt guess = translatePt(coreW/2, coreH/2, bwSpiralSearch(bwCore, bwClip));
36  
      //print("Guessed:  " + guess);
37  
      if (guess == null) guess = Pt(outerW/2, outerH/2);
38  
      sum += ptSquaredDistance(solution, guess);
39  
    }
40  
    heatMap[y*leewayX+x] = sum;
41  
  }
42  
  
43  
  BWImage heatMapImage() {
44  
    //double max = doubleMax(heatMap);
45  
    double max = (outerW-coreW)*(outerH-coreH)/gain*trials;
46  
    BWImage img = new(leewayX, leewayY);
47  
    int i = 0;
48  
    for y to leewayY:
49  
      for x to leewayX:
50  
        img.setPixel(x, y, /*1f-*/(float) doubleRatio(heatMap[i++], max));
51  
    ret img;
52  
  }
53  
  
54  
  BufferedImage mixedWithHeatMap() {
55  
    ret combineBWImagesToColor(scaledInputImage, Color.red, bwBlackBorder(coreW/2.0, coreH/2.0, heatMapImage()), Color.green);
56  
  }
57  
}

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: 225 / 538
Version history: 20 change(s)
Referenced in: [show references]