@@ -11,6 +11,7 @@ namespace Accord.Imaging
11
11
using System ;
12
12
using System . Drawing ;
13
13
using System . Drawing . Imaging ;
14
+ using Accord . Math ;
14
15
15
16
/// <summary>
16
17
/// Integral image.
@@ -52,12 +53,20 @@ namespace Accord.Imaging
52
53
public class IntegralImage : ICloneable
53
54
{
54
55
/// <summary>
55
- /// 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.
56
65
/// </summary>
57
66
///
58
67
/// <remarks>See remarks to <see cref="InternalData"/> property.</remarks>
59
68
///
60
- protected readonly uint [ , ] integralImage = null ;
69
+ protected uint [ , ] integralImage = null ;
61
70
62
71
// image's width and height
63
72
private readonly int width ;
@@ -79,6 +88,23 @@ public int Height
79
88
get { return height ; }
80
89
}
81
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
+
82
108
/// <summary>
83
109
/// Provides access to internal array keeping integral image data.
84
110
/// </summary>
@@ -91,9 +117,25 @@ public int Height
91
117
/// rectangles' sums.</note></para>
92
118
/// </remarks>
93
119
///
120
+ [ Obsolete ( "Please use Matrix property instead." ) ]
94
121
public uint [ , ] InternalData
95
122
{
96
- 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
+ }
97
139
}
98
140
99
141
/// <summary>
@@ -103,15 +145,15 @@ public int Height
103
145
/// <param name="width">Image width.</param>
104
146
/// <param name="height">Image height.</param>
105
147
///
106
- /// <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
107
149
/// class directly. To create an instance of this class <see cref="FromBitmap(Bitmap)"/> or
108
150
/// <see cref="FromBitmap(BitmapData)"/> method should be used.</remarks>
109
151
///
110
152
protected IntegralImage ( int width , int height )
111
153
{
112
154
this . width = width ;
113
155
this . height = height ;
114
- integralImage = new uint [ height + 1 , width + 1 ] ;
156
+ this . matrix = Jagged . Zeros < uint > ( height + 1 , width + 1 ) ;
115
157
}
116
158
117
159
/// <summary>
@@ -129,7 +171,7 @@ public static IntegralImage FromBitmap(Bitmap image)
129
171
// check image format
130
172
if ( image . PixelFormat != PixelFormat . Format8bppIndexed )
131
173
{
132
- throw new UnsupportedImageFormatException ( "Source image can be graysclae (8 bpp indexed) image only." ) ;
174
+ throw new UnsupportedImageFormatException ( "Source image can be grayscale (8 bpp indexed) image only." ) ;
133
175
}
134
176
135
177
// lock source image
@@ -174,7 +216,7 @@ public static IntegralImage FromBitmap(UnmanagedImage image)
174
216
// check image format
175
217
if ( image . PixelFormat != PixelFormat . Format8bppIndexed )
176
218
{
177
- throw new ArgumentException ( "Source image can be graysclae (8 bpp indexed) image only." ) ;
219
+ throw new ArgumentException ( "Source image can be grayscale (8 bpp indexed) image only." ) ;
178
220
}
179
221
180
222
// get source image size
@@ -184,7 +226,7 @@ public static IntegralImage FromBitmap(UnmanagedImage image)
184
226
185
227
// create integral image
186
228
var im = new IntegralImage ( width , height ) ;
187
- uint [ , ] integralImage = im . integralImage ;
229
+ uint [ ] [ ] matrix = im . matrix ;
188
230
189
231
// do the job
190
232
unsafe
@@ -203,7 +245,7 @@ public static IntegralImage FromBitmap(UnmanagedImage image)
203
245
204
246
rowSum += * src ;
205
247
206
- integralImage [ y , x ] = rowSum + integralImage [ y - 1 , x ] ;
248
+ matrix [ y ] [ x ] = rowSum + matrix [ y - 1 ] [ x ] ;
207
249
}
208
250
src += offset ;
209
251
}
@@ -240,7 +282,7 @@ public uint GetRectangleSum(int x1, int y1, int x2, int y2)
240
282
if ( x2 > width ) x2 = width ;
241
283
if ( y2 > height ) y2 = height ;
242
284
243
- 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 ] ;
244
286
}
245
287
246
288
/// <summary>
@@ -256,7 +298,7 @@ public uint GetRectangleSum(int x1, int y1, int x2, int y2)
256
298
/// <remarks><para>The method calculates horizontal wavelet, which is a difference
257
299
/// of two horizontally adjacent boxes' sums, i.e. <b>A-B</b>. A is the sum of rectangle with coordinates
258
300
/// (x, y-radius, x+radius-1, y+radius-1). B is the sum of rectangle with coordinates
259
- /// (x-radius, y-radius, x-1, y+radiys -1).</para></remarks>
301
+ /// (x-radius, y-radius, x-1, y+radius -1).</para></remarks>
260
302
///
261
303
public int GetHaarXWavelet ( int x , int y , int radius )
262
304
{
@@ -313,7 +355,7 @@ public uint GetRectangleSumUnsafe(int x1, int y1, int x2, int y2)
313
355
x2 ++ ;
314
356
y2 ++ ;
315
357
316
- 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 ] ;
317
359
}
318
360
319
361
/// <summary>
@@ -385,7 +427,7 @@ public float GetRectangleMean(int x1, int y1, int x2, int y2)
385
427
if ( y2 > height ) y2 = height ;
386
428
387
429
// return sum divided by actual rectangles size
388
- 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 ] ) /
389
431
( double ) ( ( x2 - x1 ) * ( y2 - y1 ) ) ) ;
390
432
}
391
433
@@ -408,7 +450,7 @@ public float GetRectangleMeanUnsafe(int x1, int y1, int x2, int y2)
408
450
y2 ++ ;
409
451
410
452
// return sum divided by actual rectangles size
411
- 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 ] ) /
412
454
( double ) ( ( x2 - x1 ) * ( y2 - y1 ) ) ) ;
413
455
}
414
456
0 commit comments