|
@@ -80,13 +80,18 @@ NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example )
|
|
|
for ( int v = -halfwsy; v <= halfwsy; v++ )
|
|
|
for ( int u = -halfwsx; u <= halfwsx; u++ )
|
|
|
{
|
|
|
- if ( x+u > 0
|
|
|
- && x+u < xsize
|
|
|
- && y+v > 0
|
|
|
- && y+v < ysize
|
|
|
+ int uu = u;
|
|
|
+ int vv = v;
|
|
|
+ if (x+u < 0 || x+u >= xsize) uu=-u;
|
|
|
+ if (y+v < 0 || y+v >= ysize) vv=-v;
|
|
|
+
|
|
|
+ if ( x+uu > 0
|
|
|
+ && x+uu < xsize
|
|
|
+ && y+vv > 0
|
|
|
+ && y+vv < ysize
|
|
|
&& k < vec.size() )
|
|
|
{
|
|
|
- vec[k] = img.get(x+u,y+v);
|
|
|
+ vec[k] = img.get(x+uu,y+vv);
|
|
|
}
|
|
|
k++;
|
|
|
}
|
|
@@ -103,8 +108,6 @@ int ConvolutionFeature::getParameterLength() const
|
|
|
|
|
|
void ConvolutionFeature::setParameterVector( const Vector & vec )
|
|
|
{
|
|
|
- double sum = 0.0;
|
|
|
-
|
|
|
if ( beta->size() == vec.size() )
|
|
|
{
|
|
|
int i = 0;
|
|
@@ -112,14 +115,13 @@ void ConvolutionFeature::setParameterVector( const Vector & vec )
|
|
|
it != beta->end(); ++it, i++ )
|
|
|
{
|
|
|
*it = vec[i];
|
|
|
- sum += vec[i];
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
std::cerr << "ConvolutionFeature::setParameterVector: Vector sizes do not match! Could not update parameter vector..." << std::endl;
|
|
|
|
|
|
if ( beta->Sum() != 1.0 )
|
|
|
- (*beta) /= sum;
|
|
|
+ beta->normalizeL2();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -146,13 +148,17 @@ double ConvolutionFeature::val ( const Example *example ) const
|
|
|
for ( int v = -halfwsy; v <= halfwsy; v++ )
|
|
|
for ( int u = -halfwsx; u <= halfwsx; u++, k++ )
|
|
|
{
|
|
|
- if ( x+u > 0
|
|
|
- && x+u < xsize
|
|
|
- && y+v > 0
|
|
|
- && y+v < ysize
|
|
|
+ int uu = u;
|
|
|
+ int vv = v;
|
|
|
+ if (x+u < 0 || x+u >= xsize) uu=-u;
|
|
|
+ if (y+v < 0 || y+v >= ysize) vv=-v;
|
|
|
+ if ( x+uu > 0
|
|
|
+ && x+uu < xsize
|
|
|
+ && y+vv > 0
|
|
|
+ && y+vv < ysize
|
|
|
&& k < beta->size() )
|
|
|
{
|
|
|
- val1 += (double)img.get(x+u,y+v) * beta->operator [](k);
|
|
|
+ val1 += (double)img.get(x+uu,y+vv) * beta->operator [](k);
|
|
|
}
|
|
|
}
|
|
|
|