Commit 1dffd4cd authored by Davis King's avatar Davis King

Changed poly_image to allow the user to decide if intensity normalization

should be used.
parent 9207d11e
......@@ -43,6 +43,7 @@ namespace dlib
void clear (
)
{
normalize = true;
poly_coef.clear();
order = 3;
window_size = 13;
......@@ -89,10 +90,21 @@ namespace dlib
filters = build_separable_poly_filters(order, window_size);
}
bool uses_normalization (
) const { return normalize; }
void set_normalization (
bool normalization
)
{
normalize = normalization;
}
void copy_configuration (
const poly_image& item
)
{
normalize = item.normalize;
if (order != item.order ||
window_size != item.window_size)
{
......@@ -116,27 +128,40 @@ namespace dlib
des.set_size(get_num_dimensions());
array2d<float> coef0;
rectangle rect = filter_image(img, coef0, filters[0]);
num_rows = rect.height();
num_cols = rect.width();
for (unsigned long i = 1; i < filters.size(); ++i)
if (normalize)
{
filter_image(img, poly_coef[i-1], filters[i]);
array2d<float> coef0;
rectangle rect = filter_image(img, coef0, filters[0]);
num_rows = rect.height();
num_cols = rect.width();
// intensity normalize everything
for (long r = 0; r < coef0.nr(); ++r)
for (unsigned long i = 1; i < filters.size(); ++i)
{
for (long c = 0; c < coef0.nc(); ++c)
filter_image(img, poly_coef[i-1], filters[i]);
// intensity normalize everything
for (long r = 0; r < coef0.nr(); ++r)
{
if (coef0[r][c] >= 1)
poly_coef[i-1][r][c] /= coef0[r][c];
else
poly_coef[i-1][r][c] = 0;
for (long c = 0; c < coef0.nc(); ++c)
{
if (coef0[r][c] >= 1)
poly_coef[i-1][r][c] /= coef0[r][c];
else
poly_coef[i-1][r][c] = 0;
}
}
}
}
else
{
rectangle rect;
for (unsigned long i = 0; i < filters.size(); ++i)
{
rect = filter_image(img, poly_coef[i], filters[i]);
}
num_rows = rect.height();
num_cols = rect.width();
}
}
void unload()
......@@ -158,8 +183,15 @@ namespace dlib
long get_num_dimensions (
) const
{
// -1 because we discard the constant term of the polynomial.
return filters.size()-1;
if (normalize)
{
// -1 because we discard the constant term of the polynomial.
return filters.size()-1;
}
else
{
return filters.size();
}
}
inline const descriptor_type& operator() (
......@@ -238,6 +270,7 @@ namespace dlib
serialize(item.border_size, out);
serialize(item.num_rows, out);
serialize(item.num_cols, out);
serialize(item.normalize, out);
serialize(item.filters, out);
}
......@@ -254,6 +287,7 @@ namespace dlib
deserialize(item.border_size, in);
deserialize(item.num_rows, in);
deserialize(item.num_cols, in);
deserialize(item.normalize, in);
deserialize(item.filters, in);
}
......@@ -285,6 +319,7 @@ namespace dlib
long num_rows;
long num_cols;
bool normalize;
mutable descriptor_type des;
};
......
......@@ -23,7 +23,7 @@ namespace dlib
This object is a tool for extracting local feature descriptors from an image.
In particular, it fits polynomials to local pixel patches and allows you to
query the coefficients of these polynomials. Additionally, the coefficients
are intensity normalized by dividing them by the constant term of the fitted
may be intensity normalized by dividing them by the constant term of the fitted
polynomial and then the constant term is discarded.
Finally, the user can specify a downsampling rate. If the template argument
......@@ -105,6 +105,22 @@ namespace dlib
This is the width and height of the window in pixels.
!*/
bool uses_normalization (
) const;
/*!
ensures
- returns true if the polynomial coefficients are intensity normalized
and false otherwise.
!*/
void set_normalization (
bool normalization
);
/*!
ensures
- uses_normalization() == normalization
!*/
void copy_configuration (
const poly_image& item
);
......@@ -184,7 +200,8 @@ namespace dlib
- returns the number of dimensions in the feature vectors generated by
this object.
- In this case, this will be the number of coefficients in an order
get_order() polynomial, except for the constant term of the polynomial.
get_order() polynomial, except for the constant term of the polynomial
if uses_normalization() == true.
!*/
inline const descriptor_type& operator() (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment