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

39
LINES

< > BotCompany Repo | #1032466 // Haar - generalized Haar-like feature

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

Libraryless. Click here for Pure Java version (5184L/31K/105K).

1  
// The relationship between the white and the black part in a traditional
2  
// Haar-like feature could be much more general. Why do they have to
3  
// touch each other? Why do they need to have the same aspect ratio?
4  
// All we require is white area = black area so the subtraction makes sense.
5  
//
6  
// And even that could be lifted by applying a correction factor
7  
// (area white / area black).
8  
//
9  
// [We should generally start normalizing the result between -1
10  
// (maximum inverted match) and 1 (maximum direct match) at this point
11  
// as now we have two different areas in play so we can't really return
12  
// meaningful "pixels" anymore.]
13  
//
14  
// Finally, black and white can even overlap and the formula doesn't even change.
15  
// Although you may want to boost the result value because it's never 
16  
// going to reach -1 or 1 when there is overlap. Not sure how to do
17  
// the actual calculation for that.
18  
//
19  
// So these are... "generalized Haar features"?
20  
//
21  
// Result classification:
22  
//
23  
//   positive = match
24  
//   0        = non-match  (indifferent/not applicable)
25  
//   negative = anti-match (inverted Haar feature found)
26  
27  
srecord Haar(IIntegralImage img, DoubleRect rBlack, DoubleRect rWhite) {
28  
  double get() {
29  
    double blackArea = area(rBlack);
30  
    double whiteArea = area(rWhite);
31  
    //double overlappingArea = area(intersectDoubleRects(rBlack, rWhite));
32  
    //double boost = ?
33  
    
34  
    double whiteSum = img.pixelSum(rWhite); // this is between 0 and whiteArea*255
35  
    double blackSum = img.pixelSum(rBlack); // this is between 0 and blackArea*255
36  
37  
    ret (doubleRatio(whiteSum, whiteArea) - doubleRatio(blackSum, blackArea))/255.0;
38  
  }
39  
}

Author comment

Began life as a copy of #1009142

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, iveijnkanddl, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032466
Snippet name: Haar - generalized Haar-like feature
Eternal ID of this version: #1032466/24
Text MD5: e07a1d136ce35d3765902d2e945ef70f
Transpilation MD5: 2b3c464fc60b08173eec59f0142c1b82
Author: stefan
Category: javax / imaging
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-09 18:45:57
Source code size: 1671 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 141 / 298
Version history: 23 change(s)
Referenced in: [show references]