73 template <
typename KDATATYPE>
class TKernel {
295 template <
typename KDATATYPE2>
297 const KDATATYPE2 *
const xaxis,
const KDATATYPE2 *
const yaxis,
const KDATATYPE2 *
const zaxis,
298 const KDATATYPE2 *
const caxis,
const KDATATYPE2 *
const taxis,
const KDATATYPE2 *
const uaxis,
302 _invalidateSeparableInfos();
307 if (!xaxis || !yaxis || !zaxis || !caxis || !taxis || !uaxis){
309 _calculateRealKernelExt();
314 KDATATYPE *valuematrix =
317 for (
MLint u=0; u<ext.
u; ++u){
318 for (
MLint t=0; t<ext.
t; ++t){
319 for (
MLint c=0; c<ext.
c; ++c){
320 for (
MLint z=0; z<ext.
z; ++z){
321 for (
MLint y=0; y<ext.
y; ++y){
322 for (
MLint x=0; x<ext.
x; ++x){
323 valuematrix[b++] =
static_cast<KDATATYPE
>(xaxis[x]*yaxis[y]*zaxis[z]*caxis[c]*taxis[t]*uaxis[u]);
327 setKernel(ext,valuematrix);
329 Memory::freeMemory(valuematrix);
333 if (normalize){ manipulateKernelElements(KERN_NORMALIZE, 0); }
372 static std::vector<KDATATYPE>
get1DGauss(
size_t numSamples,
bool normalize=
true);
498 KDATATYPE* _valueTab;
516 mutable bool _areSeparabilityInfosUpToDate;
536 mutable std::vector<ImageVector> _separableCoordTab;
552 template <
typename KDATATYPE>
561 template <
typename KDATATYPE>
571 template <
typename KDATATYPE>
580 template <
typename KDATATYPE>
589 setPartialKernel(kern._tabSize, kern._coordTab, kern._valueTab);
592 _isSeparable = kern._isSeparable;
593 _areSeparabilityInfosUpToDate = kern._areSeparabilityInfosUpToDate;
594 _separableDimEntries = kern._separableDimEntries;
595 _separableOneDimExt = kern._separableOneDimExt;
596 _separableExt = kern._separableExt;
597 _separableNegExt = kern._separableNegExt;
598 _separablePosExt = kern._separablePosExt;
599 _separableCoordTab = kern._separableCoordTab;
609 template <
typename KDATATYPE>
623 template <
typename KDATATYPE>
627 _validateSeparabilityInfos();
628 return getSeparableCoordTab().size();
643 template <
typename KDATATYPE>
646 return _isSeparable ? &(getSeparableCoordTab()[getSeparableDimIndex(dim)]) : _coordTab;
655 template <
typename KDATATYPE>
658 return _isSeparable ? (_valueTab + getSeparableDimIndex(dim)) : _valueTab;
664 template <
typename KDATATYPE>
669 for (
size_t i=0; i<_tabSize; i++){ v+=_valueTab[i]; }
677 template <
typename KDATATYPE>
681 KDATATYPE v = (_tabSize==0) ?
static_cast<KDATATYPE
>(0) : _valueTab[0];
682 for (
size_t i=1; i<_tabSize; i++){
if (_valueTab[i] < v){ v = _valueTab[i]; } }
690 template <
typename KDATATYPE>
694 KDATATYPE v = (_tabSize==0) ?
static_cast<KDATATYPE
>(1) : _valueTab[0];
695 for (
size_t i=1; i<_tabSize; i++){
if (_valueTab[i] > v){ v = _valueTab[i]; } }
704 template <
typename KDATATYPE>
708 for (
size_t i=0; i<_tabSize; i++){
710 if (!(_valueTab[i] > 0)){ v += _valueTab[i]; }
719 template <
typename KDATATYPE>
723 for (
size_t i=0; i<_tabSize; i++){
if (_valueTab[i] > 0){ v += _valueTab[i]; } }
731 template <
typename KDATATYPE>
735 _invalidateSeparableInfos();
740 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] = v; }
746 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] *= v; }
752 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] += v; }
758 for (
size_t i=0; i<_tabSize; i++){
if (!
MLValueIs0WOM(_valueTab[i])) {_valueTab[i] = v/_valueTab[i]; } }
764 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] = v-_valueTab[i]; }
770 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] *= _valueTab[i]; }
777 for (
size_t i=0; i<_tabSize; i++){
782 _valueTab[i] =
static_cast<KDATATYPE
>(sqrt(
static_cast<double>(_valueTab[i])));
790 for (
size_t i=0; i<_tabSize; i++){
795 if ( (_valueTab[i] >
static_cast<KDATATYPE
>(0)) ||
MLValueIs0WOM(_valueTab[i]) ){
798 KDATATYPE buf =
static_cast<KDATATYPE
>(powl(_valueTab[i], v));
814 MLdouble invBase=1.0/log(
static_cast<double>(v));
815 for (
size_t i=0; i<_tabSize; i++){
816 KDATATYPE val = _valueTab[i];
818 if (val > 0){ _valueTab[i] =
static_cast<KDATATYPE
>(log(
static_cast<double>(val))*invBase); }
824 case KERN_NORMALIZE:{
827 KDATATYPE sum=getValueTabSum();
829 if (!
MLValueIs0WOM(sum)){ manipulateKernelElements(KERN_MULT,
static_cast<KDATATYPE
>(1./sum)); }
887 case NUM_KERN_MODIFYERS:{
888 ML_PRINT_ERROR(
"TKernel<KDATATYPE>::manipulateKernelElements(mlKernModifier mode, KDATATYPE v)",
889 ML_PROGRAMMING_ERROR,
"NUM_KERN_MODIFYERS is an invalid parameter. Ignoring kernel manipulation.");
894 ML_PRINT_ERROR(
"TKernel<KDATATYPE>::manipulateKernelElements(mlKernModifier mode, KDATATYPE v)",
895 ML_BAD_PARAMETER,
"Invalid parameter passed. Ignoring kernel manipulation.");
912 template <
typename KDATATYPE>
916 _validateSeparabilityInfos();
917 return _separableExt;
930 template <
typename KDATATYPE>
934 _validateSeparabilityInfos();
935 return _separableNegExt;
945 template <
typename KDATATYPE>
949 _validateSeparabilityInfos();
950 return _separablePosExt;
961 template <
typename KDATATYPE>
964 return SubImage::coordToIndex(x,y,z,c,t,u, size);
970 template <
typename KDATATYPE>
973 return SubImage::coordToIndex(p, size);
979 template <
typename KDATATYPE>
982 return SubImage::indexToCoord(idx, ext);
988 template <
typename KDATATYPE>
997 template <
typename KDATATYPE>
1001 ext.
c-ext.
c/2-1, ext.
t-ext.
t/2-1, ext.
u-ext.
u/2-1);
1008 template <
typename KDATATYPE>
1012 for (
size_t c=0; c < _tabSize; c++){
1013 if (_coordTab[c] == pos){
1029 template <
typename KDATATYPE>
1036 _tabSize = numElems;
1042 _valueTab =
new KDATATYPE[_tabSize];
1045 for (
size_t c=0; c < _tabSize; c++){ _coordTab[c] = coords[c]; }
1050 memcpy(_valueTab, values, _tabSize*
sizeof(KDATATYPE));
1054 KDATATYPE v =
static_cast<KDATATYPE
>(1.0/
static_cast<KDATATYPE
>(_tabSize));
1055 for (
size_t d=0; d<_tabSize; d++){ _valueTab[d] = v; }
1061 _calculateRealKernelExt();
1096 template <
typename KDATATYPE>
1100 char strLine[256]=
"";
1103 if (fieldWidth > 128){ fieldWidth=128; }
1104 if (fieldWidth < 0){ fieldWidth=0; }
1108 for (
MLint u=0; u < getExtent().u; u++){
1109 for (
MLint t=0; t < getExtent().t; t++){
1110 for (
MLint c=0; c < getExtent().c; c++){
1111 for (
MLint z=0; z < getExtent().z; z++){
1112 for (
MLint y=0; y < getExtent().y; y++){
1114 snprintf(strLine, 255,
"(*,%lld,%lld,%lld,%lld,%lld):", y, z, c, t, u);
1119 while (strlen(strLine) < 16){ strcat(strLine,
" "); }
1125 for (
MLint x=0; x < getExtent().x; x++){
1134 strLine[0] = x==0 ?
' ' :
',';
1135 MLint w= x==0 ? fieldWidth : fieldWidth+1;
1136 for (
MLint i=1; i < w; i++){ strLine[i] =
' '; }
1146 snprintf(format, 63,
"%s%%%d.%dlf",
"%s",
static_cast<MLint32>(fieldWidth),
static_cast<MLint32>(precision));
1147 snprintf(strLine, 255, format, 0==x ?
"" :
",",
static_cast<MLdouble>(_valueTab[idx]));
1165 for (
size_t c=0; c < _tabSize; c++){
1167 KDATATYPE value = _valueTab[c];
1168 snprintf(strLine, 255,
"%s:%lf\n", coord.
print(
"(",
",",
")").c_str(),
static_cast<MLdouble>(value));
1214 template <
typename KDATATYPE>
1218 std::string errStr =
"";
1219 char *copy =
nullptr;
1225 if (kernString.length() < 15){
1232 std::string str = kernString;
1235 if (str[str.length()-1] !=
'\n'){ str +=
'\n'; }
1238 MLint lineNumber = 0;
1241 MLint x=0, y=0, z=0, c=0, t=0, u=0, num=0;
1243 num = sscanf(str.c_str(),
"(%lld,%lld,%lld,%lld,%lld,%lld):%lf", &x, &y, &z, &c, &t, &u, &fValue);
1244 KDATATYPE value =
static_cast<KDATATYPE
>(fValue);
1247 _addCoordinate(
ImageVector(x,y,z,c,t,u), value,
false);
1251 num = sscanf(str.c_str(),
"(*,%lld,%lld,%lld,%lld,%lld):", &y, &z, &c, &t, &u);
1254 const size_t cPos = str.find(
':');
1255 if (cPos != std::string::npos){
1257 str.erase(0, cPos+1);
1264 while (go && (str.length() != 0)){
1265 const char ch = str[0];
1273 else if (
'\n' == ch) {
1279 else if (
',' == ch) {
1288 char *stopPos=
nullptr;
1294 const MLdouble val = strtod(copy, &stopPos);
1297 if (stopPos != copy){
1299 _addCoordinate(
ImageVector(xCoord, y,z,c,t,u),
static_cast<KDATATYPE
>(val),
false);
1303 str.erase(0, stopPos-copy);
1311 snprintf(err, 29,
" %lld", lineNumber);
1318 Memory::freeMemory(copy);
1328 const size_t pos = str.find(
'\n');
1329 if (pos != std::string::npos){
1332 str.erase(0, pos+1);
1345 _calculateRealKernelExt();
1362 template <
typename KDATATYPE>
1369 size_t maxElems = ext.
compMul();
1374 for (
size_t c=0; c<maxElems; c++){
if (mask[c]){ _tabSize++; } }
1378 _tabSize = maxElems;
1384 _valueTab =
new KDATATYPE[_tabSize];
1385 if (!_coordTab || !_valueTab){
1388 "Cannot create kernel filter tables, so tables are reset. This will probably cause other errors.");
1391 if (_coordTab && _valueTab){
1395 memcpy(_valueTab, values, _tabSize*
sizeof(KDATATYPE));
1399 KDATATYPE v =
static_cast<KDATATYPE
>(1.0/
static_cast<KDATATYPE
>(_tabSize));
1400 for (
size_t d=0; d<_tabSize; d++){ _valueTab[d] = v; }
1406 for (
size_t e=0; e<maxElems; e++){
1407 if (!mask || (mask && mask[e])){
1408 _coordTab[idx] = indexToCoord(e, ext);
1413 if (idx !=_tabSize){
1415 "Internal error. Cannot create kernel filter tables. This will probably cause other errors.");
1423 _calculateRealKernelExt();
1435 template <
typename KDATATYPE>
1442 const size_t numRows = separableRows.size() > 6 ? 6 : separableRows.size();
1445 size_t numEntries = 0;
1446 for (
size_t e=0; e < numRows; ++e){ numEntries += separableRows[e].size(); }
1449 std::vector<KDATATYPE> valueTab; valueTab.reserve(numEntries);
1450 std::vector<ImageVector> coordTab; coordTab.reserve(numEntries);
1453 for (
size_t r=0; r < numRows; ++r){
1456 const std::vector<KDATATYPE> &row = separableRows[r];
1457 const size_t numRElements = row.size();
1465 for (
size_t re=0; re < numRElements; ++re){
1468 coordTab.push_back(entryCoord);
1469 valueTab.push_back(row[re]);
1475 setPartialKernel(coordTab.size(), &(coordTab[0]), &(valueTab[0]));
1478 _validateSeparabilityInfos();
1488 template <
typename KDATATYPE>
1498 for (
MLint u=0; u < ext.
u; u++){
1499 for (
MLint t=0; t < ext.
t; t++){
1500 for (
MLint c=0; c < ext.
c; c++){
1501 for (
MLint z=0; z < ext.
z; z++){
1502 for (
MLint y=0; y < ext.
y; y++){
1503 for (
MLint x=0; x < ext.
x; x++){
1508 if ((u < getExtent().u) &&
1509 (t < getExtent().t) &&
1510 (c < getExtent().c) &&
1511 (z < getExtent().z) &&
1512 (y < getExtent().y) &&
1513 (x < getExtent().x)){
1518 _addCoordinate(addCoord, bufferKern.
getValueTab()[idx],
false);
1523 _addCoordinate(addCoord, newVal,
false);
1535 _calculateRealKernelExt();
1542 template <
typename KDATATYPE>
1546 _invalidateSeparableInfos();
1549 for (
MLint u=0; u < getExtent().u; u++){
1550 for (
MLint t=0; t < getExtent().t; t++){
1551 for (
MLint c=0; c < getExtent().c; c++){
1552 for (
MLint z=0; z < getExtent().z; z++){
1553 for (
MLint y=0; y < getExtent().y; y++){
1554 for (
MLint x=0; x < getExtent().x; x++){
1559 if (findIndex(addCoord) < 0){
1561 _addCoordinate(addCoord, newVal,
false);
1573 _calculateRealKernelExt();
1584 template <
typename KDATATYPE>
1588 _invalidateSeparableInfos();
1615 _coordTab =
nullptr;
1617 KDATATYPE *valueTab = _valueTab;
1618 _valueTab =
nullptr;
1620 size_t tabSize = _tabSize;
1626 for (
size_t e=0; e < tabSize; e++){
1637 if (sqrt(px*px + py*py + pz*pz + pc*pc + pt*pt + pu*pu) <= 1){
1638 _addCoordinate(v, valueTab[e],
false);
1649 _calculateRealKernelExt();
1659 template <
typename KDATATYPE>
1663 _invalidateSeparableInfos();
1667 _coordTab =
nullptr;
1669 KDATATYPE *valueTabBuf = _valueTab;
1670 _valueTab =
nullptr;
1672 size_t tabSizeBuf = _tabSize;
1679 if ((dimension<0) || (dimension>5)){
1684 for (
size_t e=0; e < tabSizeBuf; e++){
1685 _addCoordinate(maxP - coordTabBuf[e], valueTabBuf[e],
false);
1690 const size_t dimensionSize_t = mlrange_cast<size_t>(dimension);
1691 for (
size_t e=0; e < tabSizeBuf; e++){
1693 mirVec = coordTabBuf[e];
1696 mirVec[dimensionSize_t] = maxP[dimensionSize_t] - coordTabBuf[e][dimensionSize_t];
1699 _addCoordinate(mirVec, valueTabBuf[e],
false);
1704 delete [] coordTabBuf;
1705 coordTabBuf =
nullptr;
1706 delete [] valueTabBuf;
1707 valueTabBuf =
nullptr;
1710 _calculateRealKernelExt();
1717 template <
typename KDATATYPE>
1725 if((k!=0) && (k!=n)){
1726 for (i=1; i<(n+1); i++){ v*=i; }
1727 for (i=1; i<(k+1); i++){ v/=i; }
1728 for (i=1; i<(n-k+1); i++){ v/=i; }
1741 template <
typename KDATATYPE>
1745 std::vector<KDATATYPE> v;
1747 if (numSamples > 0){
1748 v.reserve(numSamples);
1752 for (
size_t u=0; u<numSamples; ++u){
1755 KDATATYPE val =
static_cast<KDATATYPE
>(binomialcoeff(numSamples-1, u));
1757 sum +=
static_cast<KDATATYPE
>(
mlAbs(val));
1761 if (normalize && (sum > 0)){
1762 for (
size_t u=0; u<numSamples; u++){ v[u] /= sum; }
1773 template <
typename KDATATYPE>
1777 _invalidateSeparableInfos();
1783 std::vector<KDATATYPE> vx=get1DGauss(ext.
x,
false);
1784 std::vector<KDATATYPE> vy=get1DGauss(ext.
y,
false);
1785 std::vector<KDATATYPE> vz=get1DGauss(ext.
z,
false);
1786 std::vector<KDATATYPE> vc=get1DGauss(ext.
c,
false);
1787 std::vector<KDATATYPE> vt=get1DGauss(ext.
t,
false);
1788 std::vector<KDATATYPE> vu=get1DGauss(ext.
u,
false);
1792 setKernel(ext, &(vx[0]), &(vy[0]), &(vz[0]), &(vc[0]), &(vt[0]), &(vu[0]),
true);
1799 template <
typename KDATATYPE>
1808 _valueTab =
nullptr;
1809 _coordTab =
nullptr;
1812 _isSeparable =
false;
1813 _areSeparabilityInfosUpToDate =
false;
1814 _separableDimEntries.set(0);
1815 _separableOneDimExt.set(0);
1816 _separableExt.set(0);
1817 _separableNegExt.set(0);
1818 _separablePosExt.set(0);
1819 _separableCoordTab.clear();
1826 template <
typename KDATATYPE>
1833 _areSeparabilityInfosUpToDate =
false;
1835 delete [] _valueTab;
1837 _valueTab =
nullptr;
1838 delete [] _coordTab;
1839 _coordTab =
nullptr;
1849 template <
typename KDATATYPE>
1854 KDATATYPE *newValueTab =
nullptr;
1857 _areSeparabilityInfosUpToDate =
false;
1860 size_t newTabSize = _tabSize+1;
1863 newValueTab =
new KDATATYPE[_tabSize+1];
1866 if (!newCoordTab || !newValueTab){
1867 delete [] newCoordTab;
1868 newCoordTab =
nullptr;
1869 delete [] newValueTab;
1870 newValueTab =
nullptr;
1873 "Cannot create kernel tables. Returning with invalid "
1874 "reset tables. This will probably cause other errors.");
1880 #if defined(__GNUC__)
1886 #pragma GCC diagnostic push
1887 #pragma GCC diagnostic ignored "-Wclass-memaccess"
1889 memcpy(newCoordTab, _coordTab, _tabSize *
sizeof(
ImageVector));
1890 #if defined(__GNUC__)
1891 #pragma GCC diagnostic pop
1893 memcpy(newValueTab, _valueTab, _tabSize *
sizeof(KDATATYPE));
1897 newCoordTab[_tabSize] = pos;
1898 newValueTab[_tabSize] = value;
1904 _tabSize = newTabSize;
1905 _coordTab = newCoordTab;
1906 _valueTab = newValueTab;
1909 if (update){ _calculateRealKernelExt(); }
1919 template <
typename KDATATYPE>
1927 if (getTabSize() > 0){
1928 for (
size_t c=0; c < getTabSize(); c++){
1939 _negExt = calculateNegativeExtentFromExtent(_ext);
1940 _posExt = calculatePositiveExtentFromExtent(_ext);
1943 if (!_ext.allBiggerZero()){
1946 "Kernel has invalid extents now. Continuing anyway.");
1964 template <
typename KDATATYPE>
1968 if (_isSeparable != isSeparableVal){
1969 _isSeparable = isSeparableVal;
1970 _invalidateSeparableInfos();
1978 template <
typename KDATATYPE>
1981 return _isSeparable;
1989 template <
typename KDATATYPE>
1992 _validateSeparabilityInfos();
1993 return _separableDimEntries;
2003 template <
typename KDATATYPE>
2006 _validateSeparabilityInfos();
2007 return _separableOneDimExt;
2018 template <
typename KDATATYPE>
2021 _validateSeparabilityInfos();
2022 if (dim>5){ dim = 5; }
2028 case 1:
return static_cast<size_t>(_separableDimEntries.x);
2030 case 2:
return static_cast<size_t>(_separableDimEntries.x +
2031 _separableDimEntries.y);
2033 case 3:
return static_cast<size_t>(_separableDimEntries.x +
2034 _separableDimEntries.y +
2035 _separableDimEntries.z);
2037 case 4:
return static_cast<size_t>(_separableDimEntries.x +
2038 _separableDimEntries.y +
2039 _separableDimEntries.z +
2040 _separableDimEntries.c);
2042 case 5:
return static_cast<size_t>(_separableDimEntries.x +
2043 _separableDimEntries.y +
2044 _separableDimEntries.z +
2045 _separableDimEntries.c +
2046 _separableDimEntries.t);
2058 template <
typename KDATATYPE>
2061 _validateSeparabilityInfos();
2062 return _separableCoordTab;
2068 template <
typename KDATATYPE>
2071 _areSeparabilityInfosUpToDate =
false;
2081 template <
typename KDATATYPE>
2085 if (_areSeparabilityInfosUpToDate){
return; }
2086 if (!_areSeparabilityInfosUpToDate){
2092 _separableDimEntries.set(0);
2093 _separableOneDimExt.set(0);
2094 _separableExt.set(0);
2095 _separableCoordTab.clear();
2098 while ((idx<_tabSize) && (_coordTab[idx].y < 6)){
2102 const size_t entryY = mlrange_cast<size_t>(entry.
y);
2108 _separableDimEntries[entryY]++;
2113 if (entry.
x+1 > _separableOneDimExt[entryY]){ _separableOneDimExt[entryY] = entry.
x+1; }
2124 sepCoord[entryY] = entry.
x;
2125 _separableCoordTab.push_back(sepCoord);
2133 _separableExt = _separableOneDimExt;
2134 _separableExt.fillSmallerComps(1,1);
2142 for (
size_t e=0; e < idx; ++e){
2145 for (
size_t d=0; d < 6; ++d){
2147 if (coord[d] == -1){ coord[d] = negExt[d]; }
2157 _areSeparabilityInfosUpToDate =
true;
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
Class to manage a filtering kernel for images.
virtual ~TKernel()
Destructor. Cleans up and removes instance of kernel.
void mirror(int dimension=-1)
Applies a point symmetric mirroring of all kernel elements.
std::string getKernel(bool asLines=false, MLint fieldWidth=0, MLint precision=10) const
Returns the current kernel elements and values as string: The string needs has the following format: ...
const ImageVector & getPositiveExtent() const
See getNegativeExtent().
bool isSeparable() const
Indicates whether the first 6 rows of the first kernel slice are interpreted as 1-D axes of a separab...
static ImageVector indexToCoord(MLint idx, const ImageVector &ext)
Converts an index into an array with extents ext to a coordinate.
void makeCircular()
Takes the current kernel, computes radii from the extents of the kernel and removes all kernel elemen...
static ImageVector calculateNegativeExtentFromExtent(const ImageVector &ext)
Calculate the negative extent of a kernel from a kernel extent.
static ImageVector calculatePositiveExtentFromExtent(const ImageVector &ext)
Calculate the positive extent of a kernel from a kernel extent.
void _invalidateSeparableInfos()
Invalidate separability information.
static MLldouble binomialcoeff(MLint n, MLint k)
Calculate binomial coefficients for (n) (k)
void _init()
Initialization. Should be called only by constructors.
void fillUndefinedElements(KDATATYPE newVal=0)
Fill all undefined kernel elements with newVal.
static MLint coordToIndex(const ImageVector &p, const ImageVector &size)
Converts the coordinate into the kernel with extents size to an index.
void setPartialKernel(size_t numElems, ImageVector *const coords, KDATATYPE *const values=nullptr)
Defines a set of local kernel coordinates and optionally a set of values which define the kernel elem...
size_t getTabSize() const
Returns the current number of kernel elements.
ImageVector getSeparableDimEntries() const
Returns a ImageVector with the number of entries of the separable kernel for the dimensions 0,...
KDATATYPE getMinValue() const
Return the minimum value of all kernel element values If kernel value table is empty then 0 is return...
KDATATYPE getMaxValue() const
Return the maximum value of all kernel element values If kernel value table is empty then 1 is return...
void setSeparable(bool isSeparableVal)
Set/unset a flag to indicate that the first 6 rows of the first kernel slice is considered as 1-D axe...
const TKernel & operator=(const TKernel &kern)
Assignment operator. Sets current instance to contents of kern.
void manipulateKernelElements(KernModifier mode, KDATATYPE v)
Modify all kernel element values with the value v.
TKernel()
Constructor. Builds an empty kernel.
static std::vector< KDATATYPE > get1DGauss(size_t numSamples, bool normalize=true)
Returns a vector with numSample values binomial coefficients.
std::string setKernel(const std::string &kernString)
Defines elements and values of the kernel matrix by a string.
void reset()
Reset kernel to construction state.
const ImageVector & getExtent() const
Returns the kernel extents in 6D.
ImageVector getSeparableOneDimExtents() const
Returns a vector where the components 0,...,5 contain the extent of the region spanned by the 6 separ...
const std::vector< ImageVector > & getSeparableCoordTab() const
Returns the table of with all coordinates for filtering with separable kernels.
const KDATATYPE * getValueTab(size_t dim=0) const
Gets the table of kernel element values which are currently defined.
void _clearTables()
Clear all internal (dynamic) tables.
MLint findIndex(const ImageVector &pos) const
Return index to kernel element if it exists; otherwise return -1.
KernModifier
Manipulation modes for kernel values with a given value v:
KDATATYPE getValueTabSum() const
Return the sum of all kernel element values.
void setKernel(const ImageVector &ext, const KDATATYPE2 *const xaxis, const KDATATYPE2 *const yaxis, const KDATATYPE2 *const zaxis, const KDATATYPE2 *const caxis, const KDATATYPE2 *const taxis, const KDATATYPE2 *const uaxis, bool normalize)
Defines a complete kernel matrix whose extents are defined by ext.
static MLint coordToIndex(MLint x, MLint y, MLint z, MLint c, MLint t, MLint u, const ImageVector &size)
Converts the coordinate (x,y,z,c,t,u) into the kernel to an index into an array with 6D extents given...
const ImageVector * getCoordTab(size_t dim=0) const
Gets a table of coordinates pointing to all kernel elements which are currently defined.
TKernel(const TKernel &kern)
Copy constructor. Builds a kernel with contents of kern.
void _addCoordinate(const ImageVector &pos, KDATATYPE value, bool update)
Add a new coordinate with value to the coordinate and value table.
const ImageVector & getNegativeExtent() const
The extent of the kernel to both sides.
void _calculateRealKernelExt()
Calculate the correct maximum kernel extent for used kernel elements.
size_t getSeparableDimIndex(size_t dim=0) const
Returns the index to entries of valueTab or coordTab which are related to the 1-D separable kernel fo...
void setGauss(const ImageVector &ext)
Replaces the current kernel by a normalized gauss kernel.
KDATATYPE getNegativeValueSum() const
Return the sum of all negative kernel element values.
KDATATYPE getPositiveValueSum() const
Return the sum of all positive kernel element values.
void setKernel(const ImageVector &ext, const KDATATYPE *const values=nullptr, bool *const mask=nullptr)
Defines a complete kernel matrix whose extents are defined by ext.
void _validateSeparabilityInfos() const
This method updates all members which are needed in query methods for separability properties of the ...
void setSeparableKernel(const std::vector< typename std::vector< KDATATYPE > > &separableRows)
Create kernel coordinate and value tables in separable table format, that means a 2-D kernel where ea...
void resizeKernel(const ImageVector &ext, KDATATYPE newVal=0)
Resizes the kernel to a new state and tries to maintain the previous elements if possible.
ComponentType c
Color component of the vector.
ComponentType t
Time component of the vector.
ComponentType u
Unit/Modality/User component of the vector.
ComponentType z
Z component of the vector.
ComponentType x
X component of the vector.
ComponentType y
Y component of the vector.
std::string print(const std::string &openStr="", const std::string &sepStr=" ", const std::string &termStr="", const MLint16 numDigits=-1) const
Returns the string openStr + v.array[0] + sepStr + ...
ComponentType compMul() const
Returns the product of all components. There is no check for integer overflow.
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0; otherwise, it returns false.
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
Returns true if values differ; otherwise, it returns false.
#define ML_CALCULATION_ERROR
This is an unspecific error used in some cases where the error is not very specific.
#define ML_PROGRAMMING_ERROR
A case occurred that should not appear and there are a variety of reasons, typically it is a programm...
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm,...
#define ML_NO_MEMORY
The system does not have enough memory to perform the desired operation; try to reduce application da...
#define ML_PRINT_FATAL_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_FATAL_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be du...
#define ML_PRINT_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped.
@ ML_FATAL_MEMORY_ERROR
On allocation failure, a fatal error print is done and NULL is returned.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
TKernel< MLldouble > LDoubleKernel
Kernel type with MLldouble elements.
T mlAbs(T a)
Defines ML specific abs template since only type-dependent library functions exists.
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise maximum of buffer1 and buffer2.
MLdouble KernelDataType
Define the standard data type for kernel elements to be used in this library.
TKernel< MLfloat > FloatKernel
TKernel< KernelDataType > Kernel
Standard kernel type to be used in this kernel library.
TKernel< MLdouble > DoubleKernel
Kernel type with MLdouble elements.
TImageVector< MLint > ImageVector
Defines the standard ImageVector type that is used by the ML for indexing and coordinates.