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

56
LINES

< > BotCompany Repo | #1030535 // BWIntegralImage_twoParts

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

Libraryless. Click here for Pure Java version (6782L/42K).

1  
// integral image split in 2 vertical stripes so creation is 2-parallel
2  
final sclass BWIntegralImage_twoParts implements MakesBufferedImage, IBWIntegralImage {
3  
  int w, h, th;
4  
  IBWIntegralImage top, bottom;
5  
6  
  *() {}
7  
  *(File f) { this(loadImage2(f)); }
8  
  
9  
  *(MakesBufferedImage img) { this(toBufferedImage(img)); }
10  
  
11  
  *(BufferedImage image) {
12  
    this(image, (img, idx) -> BWIntegralImage(img));
13  
  }
14  
  
15  
  *(BufferedImage image, IF2<BufferedImage, Int, IBWIntegralImage> makeSubImage) {
16  
    this(null, image, makeSubImage);
17  
  }
18  
  
19  
  *(ThreadPoolExecutor executor, BufferedImage image, IF2<BufferedImage, Int, IBWIntegralImage> makeSubImage) ctex {
20  
    w = image.getWidth();
21  
    h = image.getHeight();
22  
    th = (h+1)/2;
23  
    L<IBWIntegralImage> l = parallelEval(executor,
24  
      () -> makeSubImage.get(virtualClipBufferedImage(image, 0, 0, w, th), 0),
25  
      () -> h <= th ? null : makeSubImage.get(virtualClipBufferedImage(image, 0, th, w, h-th), 1)
26  
    );
27  
    top = first(l);
28  
    bottom = second(l);
29  
  }
30  
    
31  
  public int getIIValue(int x, int y) {
32  
    ret y < th ? top.getIIValue(x, y)
33  
      : top.getIIValue(x, th-1) + bottom.getIIValue(x, y-th);
34  
  }
35  
  
36  
  // optimization over default method
37  
  public int getPixelSum(int x1, int y1, int x2, int y2) {
38  
    if (y2 <= th)
39  
      ret top.getPixelSum(x1, y1, x2, y2);
40  
    if (y1 >= th)
41  
      ret bottom.getPixelSum(x1, y1-th, x2, y2-th);
42  
      
43  
    // rectangle straddles top and bottom stripe
44  
    //ret bwIntegralImage_sumRect(this, x1, y1, x2, y2);
45  
    int topLeft     = top.getIIValue(x1-1, y1-1);
46  
    int topRight    = top.getIIValue(x2-1, y1-1);
47  
    int mediumLeft  = top.getIIValue(x1-1, th-1);
48  
    int mediumRight = top.getIIValue(x2-1, th-1);
49  
    int bottomLeft  = bottom.getIIValue(x1-1, y2-th-1);
50  
    int bottomRight = bottom.getIIValue(x2-1, y2-th-1);
51  
    ret bottomRight-bottomLeft+mediumRight-mediumLeft+topLeft-topRight;
52  
  }
53  
  
54  
  public int getWidth() { ret w; }
55  
  public int getHeight() { ret h; }
56  
}

Author comment

Began life as a copy of #1019595

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030535
Snippet name: BWIntegralImage_twoParts
Eternal ID of this version: #1030535/28
Text MD5: 8deaef4c85b9b9f18141dd8655740077
Transpilation MD5: 3ed531335193367e5fcd9e4ba1171367
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-07 03:04:17
Source code size: 2017 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 194 / 470
Version history: 27 change(s)
Referenced in: [show references]