Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Commit ac7e9a9

Browse files
VolguninVolgunin
authored andcommitted
Add Matrix property to IntegralImage, revert InternalData for backward compartibility.
1 parent 59abb54 commit ac7e9a9

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
lines changed

Sources/Accord.Imaging/AForge.Imaging/IntegralImage.cs

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ namespace Accord.Imaging
5353
public class IntegralImage : ICloneable
5454
{
5555
/// <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.
5765
/// </summary>
5866
///
5967
/// <remarks>See remarks to <see cref="InternalData"/> property.</remarks>
6068
///
61-
protected readonly uint[][] integralImage = null;
69+
protected uint[,] integralImage = null;
6270

6371
// image's width and height
6472
private readonly int width;
@@ -80,6 +88,23 @@ public int Height
8088
get { return height; }
8189
}
8290

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+
83108
/// <summary>
84109
/// Provides access to internal array keeping integral image data.
85110
/// </summary>
@@ -92,9 +117,25 @@ public int Height
92117
/// rectangles' sums.</note></para>
93118
/// </remarks>
94119
///
95-
public uint[][] InternalData
120+
[Obsolete("Please use Matrix property instead.")]
121+
public uint[,] InternalData
96122
{
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+
}
98139
}
99140

100141
/// <summary>
@@ -104,15 +145,15 @@ public uint[][] InternalData
104145
/// <param name="width">Image width.</param>
105146
/// <param name="height">Image height.</param>
106147
///
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
108149
/// class directly. To create an instance of this class <see cref="FromBitmap(Bitmap)"/> or
109150
/// <see cref="FromBitmap(BitmapData)"/> method should be used.</remarks>
110151
///
111152
protected IntegralImage(int width, int height)
112153
{
113154
this.width = width;
114155
this.height = height;
115-
integralImage = Jagged.Zeros<uint>(height + 1, width + 1);
156+
this.matrix = Jagged.Zeros<uint>(height + 1, width + 1);
116157
}
117158

118159
/// <summary>
@@ -185,7 +226,7 @@ public static IntegralImage FromBitmap(UnmanagedImage image)
185226

186227
// create integral image
187228
var im = new IntegralImage(width, height);
188-
uint[][] integralImage = im.integralImage;
229+
uint[][] matrix = im.matrix;
189230

190231
// do the job
191232
unsafe
@@ -204,7 +245,7 @@ public static IntegralImage FromBitmap(UnmanagedImage image)
204245

205246
rowSum += *src;
206247

207-
integralImage[y][x] = rowSum + integralImage[y - 1][x];
248+
matrix[y][x] = rowSum + matrix[y - 1][x];
208249
}
209250
src += offset;
210251
}
@@ -241,7 +282,7 @@ public uint GetRectangleSum(int x1, int y1, int x2, int y2)
241282
if (x2 > width) x2 = width;
242283
if (y2 > height) y2 = height;
243284

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];
245286
}
246287

247288
/// <summary>
@@ -257,7 +298,7 @@ public uint GetRectangleSum(int x1, int y1, int x2, int y2)
257298
/// <remarks><para>The method calculates horizontal wavelet, which is a difference
258299
/// of two horizontally adjacent boxes' sums, i.e. <b>A-B</b>. A is the sum of rectangle with coordinates
259300
/// (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>
261302
///
262303
public int GetHaarXWavelet(int x, int y, int radius)
263304
{
@@ -314,7 +355,7 @@ public uint GetRectangleSumUnsafe(int x1, int y1, int x2, int y2)
314355
x2++;
315356
y2++;
316357

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];
318359
}
319360

320361
/// <summary>
@@ -386,7 +427,7 @@ public float GetRectangleMean(int x1, int y1, int x2, int y2)
386427
if (y2 > height) y2 = height;
387428

388429
// 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]) /
390431
(double)((x2 - x1) * (y2 - y1)));
391432
}
392433

@@ -409,7 +450,7 @@ public float GetRectangleMeanUnsafe(int x1, int y1, int x2, int y2)
409450
y2++;
410451

411452
// 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]) /
413454
(double)((x2 - x1) * (y2 - y1)));
414455
}
415456

Sources/Accord.Imaging/Interest Points/FREAK/FastRetinaKeypointDescriptor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ private unsafe int mean(double kx, double ky, int scale, int orientation, int po
345345
int x_right = (int)(xf + radius + 1.5); // integral image is 1px wider
346346
int y_bottom = (int)(yf + radius + 1.5); // integral image is 1px higher
347347

348-
ret_val = (int)Integral.InternalData[y_bottom][x_right]; // bottom right corner
349-
ret_val -= (int)Integral.InternalData[y_bottom][x_left];
350-
ret_val += (int)Integral.InternalData[y_top][x_left];
351-
ret_val -= (int)Integral.InternalData[y_top][x_right];
348+
ret_val = (int)Integral.Matrix[y_bottom][x_right]; // bottom right corner
349+
ret_val -= (int)Integral.Matrix[y_bottom][x_left];
350+
ret_val += (int)Integral.Matrix[y_top][x_left];
351+
ret_val -= (int)Integral.Matrix[y_top][x_right];
352352
ret_val = ret_val / ((x_right - x_left) * (y_bottom - y_top));
353353
return ret_val;
354354
}

0 commit comments

Comments
 (0)