@@ -55,7 +55,9 @@ Ref<Binarizer> HybridBinarizer::createBinarizer(Ref<LuminanceSource> source) {
55
55
}
56
56
57
57
int HybridBinarizer::initBlockIntegral () {
58
- blockIntegral_ = new Array<int >(width * height);
58
+ blockIntegralWidth = subWidth_ + 1 ;
59
+ blockIntegralHeight = subHeight_ + 1 ;
60
+ blockIntegral_ = new Array<int >(blockIntegralWidth * blockIntegralHeight);
59
61
60
62
int * integral = blockIntegral_->data ();
61
63
@@ -64,34 +66,27 @@ int HybridBinarizer::initBlockIntegral() {
64
66
// first row only
65
67
int rs = 0 ;
66
68
67
- for (int j = 0 ; j < width ; j++) {
69
+ for (int j = 0 ; j < blockIntegralWidth ; j++) {
68
70
integral[j] = 0 ;
69
71
}
70
72
71
- for (int i = 0 ; i < height; i++) {
72
- integral[i * width] = 0 ;
73
- }
74
-
75
- for (int j = 0 ; j < subWidth_; j++) {
76
- rs += blocks_[j].threshold ;
77
- integral[width + j + 1 ] = rs;
73
+ for (int i = 0 ; i < blockIntegralHeight; i++) {
74
+ integral[i * blockIntegralWidth] = 0 ;
78
75
}
79
76
80
77
// remaining cells are sum above and to the left
81
- int offset = width;
82
78
int offsetBlock = 0 ;
79
+ int offsetIntegral = 0 ;
83
80
84
- for (int i = 1 ; i < subHeight_; ++i) {
81
+ for (int i = 0 ; i < subHeight_; ++i) {
85
82
// therow = grayByte_->getByteRow(i);
86
83
offsetBlock = i * subWidth_;
87
-
84
+ offsetIntegral = (i + 1 ) * blockIntegralWidth;
88
85
rs = 0 ;
89
86
90
- offset += width;
91
-
92
87
for (int j = 0 ; j < subWidth_; ++j) {
93
88
rs += blocks_[offsetBlock + j].threshold ;
94
- integral[offset + j + 1 ] = rs + integral[offset - width + j + 1 ];
89
+ integral[offsetIntegral + j + 1 ] = rs + integral[offsetIntegral - blockIntegralWidth + j + 1 ];
95
90
}
96
91
}
97
92
@@ -201,8 +196,8 @@ void HybridBinarizer::calculateThresholdForBlock(Ref<ByteMatrix>& _luminances, i
201
196
int sum = 0 ;
202
197
// int sum2 = 0;
203
198
204
- int offset1 = (top - THRES_BLOCKSIZE) * (subWidth + 1 ) + left - THRES_BLOCKSIZE;
205
- int offset2 = (top + THRES_BLOCKSIZE + 1 ) * (subWidth + 1 ) + left - THRES_BLOCKSIZE;
199
+ int offset1 = (top - THRES_BLOCKSIZE) * blockIntegralWidth + left - THRES_BLOCKSIZE;
200
+ int offset2 = (top + THRES_BLOCKSIZE + 1 ) * blockIntegralWidth + left - THRES_BLOCKSIZE;
206
201
207
202
int blocksize = THRES_BLOCKSIZE * 2 + 1 ;
208
203
0 commit comments