45 _kernelColFunctionPtr(),
46 _kernelRowFunctionPtr(),
59 :
Kernel(width, height, kernelColFunction.getNParameters() + kernelRowFunction.getNParameters(),
61 _kernelColFunctionPtr(kernelColFunction.
clone()),
62 _kernelRowFunctionPtr(kernelRowFunction.
clone()),
64 _localRowList(height),
75 :
Kernel(width, height, spatialFunctionList),
76 _kernelColFunctionPtr(kernelColFunction.
clone()),
77 _kernelRowFunctionPtr(kernelRowFunction.
clone()),
79 _localRowList(height),
85 spatialFunctionList.
size()) {
87 os <<
"kernelColFunction.getNParameters() + kernelRowFunction.getNParameters() = "
89 <<
" != " << spatialFunctionList.
size() <<
" = "
90 <<
"spatialFunctionList.size()";
104 *(this->_kernelRowFunctionPtr)));
106 retPtr->setCtr(this->
getCtr());
114 retPtr = std::make_shared<SeparableKernel>(width, height, *_kernelColFunctionPtr,
117 retPtr = std::make_shared<SeparableKernel>(width, height, *_kernelColFunctionPtr,
118 *_kernelRowFunctionPtr);
124 bool doNormalize,
double x,
double y)
const {
125 if (
static_cast<int>(colList.
size()) != this->getWidth() ||
126 static_cast<int>(rowList.
size()) != this->getHeight()) {
128 os <<
"colList.size(), rowList.size() = (" << colList.
size() <<
", " << rowList.
size() <<
") != ("
130 <<
"kernel dimensions";
137 return basicComputeVectors(colList, rowList, doNormalize);
141 return _kernelColFunctionPtr->
clone();
145 return _kernelRowFunctionPtr->
clone();
152 <<
"..x (width) function: " << (_kernelColFunctionPtr ? _kernelColFunctionPtr->
toString() :
"None")
155 <<
"..y (rows) function: " << (_kernelRowFunctionPtr ? _kernelRowFunctionPtr->
toString() :
"None")
173 double imSum = basicComputeVectors(_localColList, _localRowList, doNormalize);
175 for (
int y = 0;
y !=
image.getHeight(); ++
y) {
178 ++colIter, ++imPtr) {
179 *imPtr = (*colIter) * _localRowList[
y];
187 unsigned int const nColParams = _kernelColFunctionPtr->
getNParameters();
188 if (ind < nColParams) {
191 _kernelRowFunctionPtr->
setParameter(ind - nColParams, value);
200 bool doNormalize)
const {
202 if (_kernelColCache.
empty()) {
203 for (
unsigned int i = 0; i != colList.
size(); ++i) {
204 double colFuncValue = (*_kernelColFunctionPtr)(_kernelX[i]);
205 colList[i] = colFuncValue;
206 colSum += colFuncValue;
214 for (
unsigned int i = 0; i != colList.
size(); ++i) {
215 double colFuncValue = cachedValues[i];
216 colList[i] = colFuncValue;
217 colSum += colFuncValue;
222 if (_kernelRowCache.
empty()) {
223 for (
unsigned int i = 0; i != rowList.
size(); ++i) {
224 double rowFuncValue = (*_kernelRowFunctionPtr)(_kernelY[i]);
225 rowList[i] = rowFuncValue;
226 rowSum += rowFuncValue;
234 for (
unsigned int i = 0; i != rowList.
size(); ++i) {
235 double rowFuncValue = cachedValues[i];
236 rowList[i] = rowFuncValue;
237 rowSum += rowFuncValue;
241 if (::
fabs(rowFuncValue - (*_kernelRowFunctionPtr)(_kernelX[i])) > 1e-2) {
243 << rowFuncValue <<
" "
244 << (*_kernelRowFunctionPtr)(_kernelX[i])
252 double imSum = colSum * rowSum;
254 if ((colSum == 0) || (rowSum == 0)) {
276 kernelCache->erase(kernelCache->begin(), kernelCache->end());
280 if (kernelCache[0].size() !=
x.size()) {
281 kernelCache->erase(kernelCache->begin(), kernelCache->end());
284 int const old_cacheSize = kernelCache->size();
291 kernelCache->erase(kernelCache->begin() +
cacheSize, kernelCache->end());
294 for (
int i = old_cacheSize; i !=
cacheSize; ++i) {
295 (*kernelCache)[i].resize(
x.size());
302 func->setParameter(0, (i + 0.5) /
static_cast<double>(
cacheSize));
303 for (
unsigned int j = 0; j !=
x.size(); ++j) {
304 (*kernelCache)[i][j] = (*func)(
x[j]);
314 _computeCache(
cacheSize, _kernelY, func, &_kernelColCache);
317 _computeCache(
cacheSize, _kernelX, func, &_kernelRowCache);