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

40
LINES

< > BotCompany Repo | #1032151 // IIPureQuad - pure = square & width/height is a power of two, quad = consists of 2*2 same-size sub-blocks [dev.]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Compilation Failed (4177L/23K).

1  
sclass IIPureQuad extends Meta implements IIntegralImage {
2  
  int imageSizeInBits; // e.g. 8 = 256*256
3  
  int[] pixelSumsByChannel; // average color of whole image stored as pixel sum
4  
  IIntegralImage[] quadrants = new[4]; // in scan line order
5  
  
6  
  int imageSize() { ret 1 << imageSizeInBits; }
7  
  int halfSize() { ret 1 << (imageSizeInBits-1); }
8  
  public int getWidth() { ret imageSize(); }
9  
  public int getHeight() { ret imageSize(); }
10  
  int pixelCount() { ret 1 << (imageSizeInBits*2); }
11  
12  
  public double getIntegralValue(int x, int y, int channel) {
13  
    int quadX = x >> (imageSizeInBits-1);  // 0 or 1
14  
    int quadY = y >> (imageSizeInBits-1);  // 0 or 1
15  
    int quadrant = quadX | (quadY << 1); // 0 to 3
16  
    int xLo = x & ~halfSize(); // clear topmost bit
17  
    int yLo = y & ~halfSize(); // clear topmost bit
18  
    
19  
    // first query quadrant we landed in
20  
    
21  
    double pixelSum = quadrants[quadrant].getIntegralValue(xLo, yLo, channel);
22  
    
23  
    // add quadrant to the left
24  
    
25  
    if (quadX != 0)
26  
      pixelSum += quadrants[quadrant-1].getIntegralValue(halfSize(), yLo, channel);
27  
      
28  
    // add quadrant above
29  
      
30  
    if (quadY != 0)
31  
      pixelSum += quadrants[quadrant-2].getIntegralValue(xLo, halfSize(), channel);
32  
      
33  
    // add full top left quadrant
34  
    
35  
    if (quadrant == 3)
36  
      pixelSum += quadrants[0].getIntegralValue(halfSize(), halfSize(), channel);
37  
      
38  
    ret pixelSum;
39  
  }
40  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032151
Snippet name: IIPureQuad - pure = square & width/height is a power of two, quad = consists of 2*2 same-size sub-blocks [dev.]
Eternal ID of this version: #1032151/6
Text MD5: 2cc54b6869e9c523e89e08afc7202196
Transpilation MD5: 464cc32bd4b24b24eb982c197fb42714
Author: stefan
Category: javax / integral imaging
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-15 00:47:43
Source code size: 1453 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 249 / 730
Version history: 5 change(s)
Referenced in: [show references]