@@ -53,12 +53,20 @@ namespace Accord.Imaging
53
53
public class IntegralImage : ICloneable
54
54
{
55
55
/// <summary>
56
- /// Intergral image's array.
56
+ /// Integral image's array.
57
+ /// </summary>
58
+ ///
59
+ /// <remarks>See remarks to <see cref="Matrix"/> property.</remarks>
60
+ ///
61
+ protected readonly uint [ ] [ ] matrix = null ;
62
+
63
+ /// <summary>
64
+ /// Integral image's array.
57
65
/// </summary>
58
66
///
59
67
/// <remarks>See remarks to <see cref="InternalData"/> property.</remarks>
60
68
///
61
- protected readonly uint [ ] [ ] integralImage = null ;
69
+ protected uint [ , ] integralImage = null ;
62
70
63
71
// image's width and height
64
72
private readonly int width ;
@@ -80,6 +88,23 @@ public int Height
80
88
get { return height ; }
81
89
}
82
90
91
+ /// <summary>
92
+ /// Provides access to internal array keeping integral image data.
93
+ /// </summary>
94
+ ///
95
+ /// <remarks>
96
+ /// <para><note>The array should be accessed by [y][x] indexing.</note></para>
97
+ ///
98
+ /// <para><note>The array's size is [<see cref="Height"/>+1, <see cref="Width"/>+1]. The first
99
+ /// row and column are filled with zeros, what is done for more efficient calculation of
100
+ /// rectangles' sums.</note></para>
101
+ /// </remarks>
102
+ ///
103
+ public uint [ ] [ ] Matrix
104
+ {
105
+ get { return matrix ; }
106
+ }
107
+
83
108
/// <summary>
84
109
/// Provides access to internal array keeping integral image data.
85
110
/// </summary>
@@ -92,9 +117,25 @@ public int Height
92
117
/// rectangles' sums.</note></para>
93
118
/// </remarks>
94
119
///
95
- public uint [ ] [ ] InternalData
120
+ [ Obsolete ( "Please use Matrix property instead." ) ]
121
+ public uint [ , ] InternalData
96
122
{
97
- get { return integralImage ; }
123
+ get
124
+ {
125
+ if ( integralImage == null )
126
+ {
127
+ integralImage = new uint [ height + 1 , width + 1 ] ;
128
+ for ( int y = 0 ; y <= height ; y ++ )
129
+ {
130
+ for ( int x = 0 ; x <= width ; x ++ )
131
+ {
132
+ integralImage [ y , x ] = matrix [ y ] [ x ] ;
133
+ }
134
+ }
135
+ }
136
+
137
+ return integralImage ;
138
+ }
98
139
}
99
140
100
141
/// <summary>
@@ -104,15 +145,15 @@ public uint[][] InternalData
104
145
/// <param name="width">Image width.</param>
105
146
/// <param name="height">Image height.</param>
106
147
///
107
- /// <remarks>The constractor is protected, what makes it imposible to instantiate this
148
+ /// <remarks>The constructor is protected, what makes it impossible to instantiate this
108
149
/// class directly. To create an instance of this class <see cref="FromBitmap(Bitmap)"/> or
109
150
/// <see cref="FromBitmap(BitmapData)"/> method should be used.</remarks>
110
151
///
111
152
protected IntegralImage ( int width , int height )
112
153
{
113
154
this . width = width ;
114
155
this . height = height ;
115
- integralImage = Jagged . Zeros < uint > ( height + 1 , width + 1 ) ;
156
+ this . matrix = Jagged . Zeros < uint > ( height + 1 , width + 1 ) ;
116
157
}
117
158
118
159
/// <summary>
@@ -185,7 +226,7 @@ public static IntegralImage FromBitmap(UnmanagedImage image)
185
226
186
227
// create integral image
187
228
var im = new IntegralImage ( width , height ) ;
188
- uint [ ] [ ] integralImage = im . integralImage ;
229
+ uint [ ] [ ] matrix = im . matrix ;
189
230
190
231
// do the job
191
232
unsafe
@@ -204,7 +245,7 @@ public static IntegralImage FromBitmap(UnmanagedImage image)
204
245
205
246
rowSum += * src ;
206
247
207
- integralImage [ y ] [ x ] = rowSum + integralImage [ y - 1 ] [ x ] ;
248
+ matrix [ y ] [ x ] = rowSum + matrix [ y - 1 ] [ x ] ;
208
249
}
209
250
src += offset ;
210
251
}
@@ -241,7 +282,7 @@ public uint GetRectangleSum(int x1, int y1, int x2, int y2)
241
282
if ( x2 > width ) x2 = width ;
242
283
if ( y2 > height ) y2 = height ;
243
284
244
- return integralImage [ y2 ] [ x2 ] + integralImage [ y1 ] [ x1 ] - integralImage [ y2 ] [ x1 ] - integralImage [ y1 ] [ x2 ] ;
285
+ return matrix [ y2 ] [ x2 ] + matrix [ y1 ] [ x1 ] - matrix [ y2 ] [ x1 ] - matrix [ y1 ] [ x2 ] ;
245
286
}
246
287
247
288
/// <summary>
@@ -257,7 +298,7 @@ public uint GetRectangleSum(int x1, int y1, int x2, int y2)
257
298
/// <remarks><para>The method calculates horizontal wavelet, which is a difference
258
299
/// of two horizontally adjacent boxes' sums, i.e. <b>A-B</b>. A is the sum of rectangle with coordinates
259
300
/// (x, y-radius, x+radius-1, y+radius-1). B is the sum of rectangle with coordinates
260
- /// (x-radius, y-radius, x-1, y+radiys -1).</para></remarks>
301
+ /// (x-radius, y-radius, x-1, y+radius -1).</para></remarks>
261
302
///
262
303
public int GetHaarXWavelet ( int x , int y , int radius )
263
304
{
@@ -314,7 +355,7 @@ public uint GetRectangleSumUnsafe(int x1, int y1, int x2, int y2)
314
355
x2 ++ ;
315
356
y2 ++ ;
316
357
317
- return integralImage [ y2 ] [ x2 ] + integralImage [ y1 ] [ x1 ] - integralImage [ y2 ] [ x1 ] - integralImage [ y1 ] [ x2 ] ;
358
+ return matrix [ y2 ] [ x2 ] + matrix [ y1 ] [ x1 ] - matrix [ y2 ] [ x1 ] - matrix [ y1 ] [ x2 ] ;
318
359
}
319
360
320
361
/// <summary>
@@ -386,7 +427,7 @@ public float GetRectangleMean(int x1, int y1, int x2, int y2)
386
427
if ( y2 > height ) y2 = height ;
387
428
388
429
// return sum divided by actual rectangles size
389
- return ( float ) ( ( double ) ( integralImage [ y2 ] [ x2 ] + integralImage [ y1 ] [ x1 ] - integralImage [ y2 ] [ x1 ] - integralImage [ y1 ] [ x2 ] ) /
430
+ return ( float ) ( ( double ) ( matrix [ y2 ] [ x2 ] + matrix [ y1 ] [ x1 ] - matrix [ y2 ] [ x1 ] - matrix [ y1 ] [ x2 ] ) /
390
431
( double ) ( ( x2 - x1 ) * ( y2 - y1 ) ) ) ;
391
432
}
392
433
@@ -409,7 +450,7 @@ public float GetRectangleMeanUnsafe(int x1, int y1, int x2, int y2)
409
450
y2 ++ ;
410
451
411
452
// return sum divided by actual rectangles size
412
- return ( float ) ( ( double ) ( integralImage [ y2 ] [ x2 ] + integralImage [ y1 ] [ x1 ] - integralImage [ y2 ] [ x1 ] - integralImage [ y1 ] [ x2 ] ) /
453
+ return ( float ) ( ( double ) ( matrix [ y2 ] [ x2 ] + matrix [ y1 ] [ x1 ] - matrix [ y2 ] [ x1 ] - matrix [ y1 ] [ x2 ] ) /
413
454
( double ) ( ( x2 - x1 ) * ( y2 - y1 ) ) ) ;
414
455
}
415
456
0 commit comments