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);
440 #if ML_DEPRECATED_SINCE(3,5,0)
449 inline ML_DEPRECATED KDATATYPE getNegValueSum()
const {
return getNegativeValueSum(); }
453 inline ML_DEPRECATED KDATATYPE getPosValueSum()
const {
return getPositiveValueSum(); }
538 KDATATYPE* _valueTab;
556 mutable bool _areSeparabilityInfosUpToDate;
576 mutable std::vector<ImageVector> _separableCoordTab;
592 template <
typename KDATATYPE>
601 template <
typename KDATATYPE>
611 template <
typename KDATATYPE>
620 template <
typename KDATATYPE>
629 setPartialKernel(kern._tabSize, kern._coordTab, kern._valueTab);
632 _isSeparable = kern._isSeparable;
633 _areSeparabilityInfosUpToDate = kern._areSeparabilityInfosUpToDate;
634 _separableDimEntries = kern._separableDimEntries;
635 _separableOneDimExt = kern._separableOneDimExt;
636 _separableExt = kern._separableExt;
637 _separableNegExt = kern._separableNegExt;
638 _separablePosExt = kern._separablePosExt;
639 _separableCoordTab = kern._separableCoordTab;
649 template <
typename KDATATYPE>
663 template <
typename KDATATYPE>
667 _validateSeparabilityInfos();
668 return getSeparableCoordTab().size();
683 template <
typename KDATATYPE>
686 return _isSeparable ? &(getSeparableCoordTab()[getSeparableDimIndex(dim)]) : _coordTab;
695 template <
typename KDATATYPE>
698 return _isSeparable ? (_valueTab + getSeparableDimIndex(dim)) : _valueTab;
704 template <
typename KDATATYPE>
709 for (
size_t i=0; i<_tabSize; i++){ v+=_valueTab[i]; }
717 template <
typename KDATATYPE>
721 KDATATYPE v = (_tabSize==0) ?
static_cast<KDATATYPE
>(0) : _valueTab[0];
722 for (
size_t i=1; i<_tabSize; i++){
if (_valueTab[i] < v){ v = _valueTab[i]; } }
730 template <
typename KDATATYPE>
734 KDATATYPE v = (_tabSize==0) ?
static_cast<KDATATYPE
>(1) : _valueTab[0];
735 for (
size_t i=1; i<_tabSize; i++){
if (_valueTab[i] > v){ v = _valueTab[i]; } }
744 template <
typename KDATATYPE>
748 for (
size_t i=0; i<_tabSize; i++){
750 if (!(_valueTab[i] > 0)){ v += _valueTab[i]; }
759 template <
typename KDATATYPE>
763 for (
size_t i=0; i<_tabSize; i++){
if (_valueTab[i] > 0){ v += _valueTab[i]; } }
771 template <
typename KDATATYPE>
775 _invalidateSeparableInfos();
780 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] = v; }
786 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] *= v; }
792 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] += v; }
798 for (
size_t i=0; i<_tabSize; i++){
if (!
MLValueIs0WOM(_valueTab[i])) {_valueTab[i] = v/_valueTab[i]; } }
804 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] = v-_valueTab[i]; }
810 for (
size_t i=0; i<_tabSize; i++){ _valueTab[i] *= _valueTab[i]; }
817 for (
size_t i=0; i<_tabSize; i++){
822 _valueTab[i] =
static_cast<KDATATYPE
>(sqrt(
static_cast<double>(_valueTab[i])));
830 for (
size_t i=0; i<_tabSize; i++){
835 if ( (_valueTab[i] >
static_cast<KDATATYPE
>(0)) ||
MLValueIs0WOM(_valueTab[i]) ){
838 KDATATYPE buf =
static_cast<KDATATYPE
>(powl(_valueTab[i], v));
854 MLdouble invBase=1.0/log(
static_cast<double>(v));
855 for (
size_t i=0; i<_tabSize; i++){
856 KDATATYPE val = _valueTab[i];
858 if (val > 0){ _valueTab[i] =
static_cast<KDATATYPE
>(log(
static_cast<double>(val))*invBase); }
864 case KERN_NORMALIZE:{
867 KDATATYPE sum=getValueTabSum();
869 if (!
MLValueIs0WOM(sum)){ manipulateKernelElements(KERN_MULT,
static_cast<KDATATYPE
>(1./sum)); }
927 case NUM_KERN_MODIFYERS:{
928 ML_PRINT_ERROR(
"TKernel<KDATATYPE>::manipulateKernelElements(mlKernModifier mode, KDATATYPE v)",
929 ML_PROGRAMMING_ERROR,
"NUM_KERN_MODIFYERS is an invalid parameter. Ignoring kernel manipulation.");
934 ML_PRINT_ERROR(
"TKernel<KDATATYPE>::manipulateKernelElements(mlKernModifier mode, KDATATYPE v)",
935 ML_BAD_PARAMETER,
"Invalid parameter passed. Ignoring kernel manipulation.");
952 template <
typename KDATATYPE>
956 _validateSeparabilityInfos();
957 return _separableExt;
970 template <
typename KDATATYPE>
974 _validateSeparabilityInfos();
975 return _separableNegExt;
985 template <
typename KDATATYPE>
989 _validateSeparabilityInfos();
990 return _separablePosExt;
1001 template <
typename KDATATYPE>
1004 return SubImage::coordToIndex(x,y,z,c,t,u, size);
1010 template <
typename KDATATYPE>
1013 return SubImage::coordToIndex(p, size);
1019 template <
typename KDATATYPE>
1022 return SubImage::indexToCoord(idx, ext);
1028 template <
typename KDATATYPE>
1037 template <
typename KDATATYPE>
1041 ext.
c-ext.
c/2-1, ext.
t-ext.
t/2-1, ext.
u-ext.
u/2-1);
1048 template <
typename KDATATYPE>
1052 for (
size_t c=0; c < _tabSize; c++){
1053 if (_coordTab[c] == pos){
1069 template <
typename KDATATYPE>
1076 _tabSize = numElems;
1082 _valueTab =
new KDATATYPE[_tabSize];
1085 for (
size_t c=0; c < _tabSize; c++){ _coordTab[c] = coords[c]; }
1090 memcpy(_valueTab, values, _tabSize*
sizeof(KDATATYPE));
1094 KDATATYPE v =
static_cast<KDATATYPE
>(1.0/
static_cast<KDATATYPE
>(_tabSize));
1095 for (
size_t d=0; d<_tabSize; d++){ _valueTab[d] = v; }
1101 _calculateRealKernelExt();
1136 template <
typename KDATATYPE>
1140 char strLine[256]=
"";
1143 if (fieldWidth > 128){ fieldWidth=128; }
1144 if (fieldWidth < 0){ fieldWidth=0; }
1148 for (
MLint u=0; u < getExtent().u; u++){
1149 for (
MLint t=0; t < getExtent().t; t++){
1150 for (
MLint c=0; c < getExtent().c; c++){
1151 for (
MLint z=0; z < getExtent().z; z++){
1152 for (
MLint y=0; y < getExtent().y; y++){
1154 snprintf(strLine, 255,
"(*,%lld,%lld,%lld,%lld,%lld):", y, z, c, t, u);
1159 while (strlen(strLine) < 16){ strcat(strLine,
" "); }
1165 for (
MLint x=0; x < getExtent().x; x++){
1174 strLine[0] = x==0 ?
' ' :
',';
1175 MLint w= x==0 ? fieldWidth : fieldWidth+1;
1176 for (
MLint i=1; i < w; i++){ strLine[i] =
' '; }
1186 snprintf(format, 63,
"%s%%%d.%dlf",
"%s",
static_cast<MLint32>(fieldWidth),
static_cast<MLint32>(precision));
1187 snprintf(strLine, 255, format, 0==x ?
"" :
",",
static_cast<MLdouble>(_valueTab[idx]));
1205 for (
size_t c=0; c < _tabSize; c++){
1207 KDATATYPE value = _valueTab[c];
1208 snprintf(strLine, 255,
"%s:%lf\n", coord.
print(
"(",
",",
")").c_str(),
static_cast<MLdouble>(value));
1254 template <
typename KDATATYPE>
1258 std::string errStr =
"";
1259 char *copy =
nullptr;
1265 if (kernString.length() < 15){
1272 std::string str = kernString;
1275 if (str[str.length()-1] !=
'\n'){ str +=
'\n'; }
1278 MLint lineNumber = 0;
1281 MLint x=0, y=0, z=0, c=0, t=0, u=0, num=0;
1283 num = sscanf(str.c_str(),
"(%lld,%lld,%lld,%lld,%lld,%lld):%lf", &x, &y, &z, &c, &t, &u, &fValue);
1284 KDATATYPE value =
static_cast<KDATATYPE
>(fValue);
1287 _addCoordinate(
ImageVector(x,y,z,c,t,u), value,
false);
1291 num = sscanf(str.c_str(),
"(*,%lld,%lld,%lld,%lld,%lld):", &y, &z, &c, &t, &u);
1294 const size_t cPos = str.find(
':');
1295 if (cPos != std::string::npos){
1297 str.erase(0, cPos+1);
1304 while (go && (str.length() != 0)){
1305 const char ch = str[0];
1313 else if (
'\n' == ch) {
1319 else if (
',' == ch) {
1328 char *stopPos=
nullptr;
1334 const MLdouble val = strtod(copy, &stopPos);
1337 if (stopPos != copy){
1339 _addCoordinate(
ImageVector(xCoord, y,z,c,t,u),
static_cast<KDATATYPE
>(val),
false);
1343 str.erase(0, stopPos-copy);
1351 snprintf(err, 29,
" %lld", lineNumber);
1358 Memory::freeMemory(copy);
1368 const size_t pos = str.find(
'\n');
1369 if (pos != std::string::npos){
1372 str.erase(0, pos+1);
1385 _calculateRealKernelExt();
1402 template <
typename KDATATYPE>
1409 size_t maxElems = ext.
compMul();
1414 for (
size_t c=0; c<maxElems; c++){
if (mask[c]){ _tabSize++; } }
1418 _tabSize = maxElems;
1424 _valueTab =
new KDATATYPE[_tabSize];
1425 if (!_coordTab || !_valueTab){
1428 "Cannot create kernel filter tables, so tables are reset. This will probably cause other errors.");
1431 if (_coordTab && _valueTab){
1435 memcpy(_valueTab, values, _tabSize*
sizeof(KDATATYPE));
1439 KDATATYPE v =
static_cast<KDATATYPE
>(1.0/
static_cast<KDATATYPE
>(_tabSize));
1440 for (
size_t d=0; d<_tabSize; d++){ _valueTab[d] = v; }
1446 for (
size_t e=0; e<maxElems; e++){
1447 if (!mask || (mask && mask[e])){
1448 _coordTab[idx] = indexToCoord(e, ext);
1453 if (idx !=_tabSize){
1455 "Internal error. Cannot create kernel filter tables. This will probably cause other errors.");
1463 _calculateRealKernelExt();
1475 template <
typename KDATATYPE>
1482 const size_t numRows = separableRows.size() > 6 ? 6 : separableRows.size();
1485 size_t numEntries = 0;
1486 for (
size_t e=0; e < numRows; ++e){ numEntries += separableRows[e].size(); }
1489 std::vector<KDATATYPE> valueTab; valueTab.reserve(numEntries);
1490 std::vector<ImageVector> coordTab; coordTab.reserve(numEntries);
1493 for (
size_t r=0; r < numRows; ++r){
1496 const std::vector<KDATATYPE> &row = separableRows[r];
1497 const size_t numRElements = row.size();
1505 for (
size_t re=0; re < numRElements; ++re){
1508 coordTab.push_back(entryCoord);
1509 valueTab.push_back(row[re]);
1515 setPartialKernel(coordTab.size(), &(coordTab[0]), &(valueTab[0]));
1518 _validateSeparabilityInfos();
1528 template <
typename KDATATYPE>
1538 for (
MLint u=0; u < ext.
u; u++){
1539 for (
MLint t=0; t < ext.
t; t++){
1540 for (
MLint c=0; c < ext.
c; c++){
1541 for (
MLint z=0; z < ext.
z; z++){
1542 for (
MLint y=0; y < ext.
y; y++){
1543 for (
MLint x=0; x < ext.
x; x++){
1548 if ((u < getExtent().u) &&
1549 (t < getExtent().t) &&
1550 (c < getExtent().c) &&
1551 (z < getExtent().z) &&
1552 (y < getExtent().y) &&
1553 (x < getExtent().x)){
1558 _addCoordinate(addCoord, bufferKern.
getValueTab()[idx],
false);
1563 _addCoordinate(addCoord, newVal,
false);
1575 _calculateRealKernelExt();
1582 template <
typename KDATATYPE>
1586 _invalidateSeparableInfos();
1589 for (
MLint u=0; u < getExtent().u; u++){
1590 for (
MLint t=0; t < getExtent().t; t++){
1591 for (
MLint c=0; c < getExtent().c; c++){
1592 for (
MLint z=0; z < getExtent().z; z++){
1593 for (
MLint y=0; y < getExtent().y; y++){
1594 for (
MLint x=0; x < getExtent().x; x++){
1599 if (findIndex(addCoord) < 0){
1601 _addCoordinate(addCoord, newVal,
false);
1613 _calculateRealKernelExt();
1624 template <
typename KDATATYPE>
1628 _invalidateSeparableInfos();
1655 _coordTab =
nullptr;
1657 KDATATYPE *valueTab = _valueTab;
1658 _valueTab =
nullptr;
1660 size_t tabSize = _tabSize;
1666 for (
size_t e=0; e < tabSize; e++){
1677 if (sqrt(px*px + py*py + pz*pz + pc*pc + pt*pt + pu*pu) <= 1){
1678 _addCoordinate(v, valueTab[e],
false);
1689 _calculateRealKernelExt();
1699 template <
typename KDATATYPE>
1703 _invalidateSeparableInfos();
1707 _coordTab =
nullptr;
1709 KDATATYPE *valueTabBuf = _valueTab;
1710 _valueTab =
nullptr;
1712 size_t tabSizeBuf = _tabSize;
1719 if ((dimension<0) || (dimension>5)){
1724 for (
size_t e=0; e < tabSizeBuf; e++){
1725 _addCoordinate(maxP - coordTabBuf[e], valueTabBuf[e],
false);
1730 const size_t dimensionSize_t = mlrange_cast<size_t>(dimension);
1731 for (
size_t e=0; e < tabSizeBuf; e++){
1733 mirVec = coordTabBuf[e];
1736 mirVec[dimensionSize_t] = maxP[dimensionSize_t] - coordTabBuf[e][dimensionSize_t];
1739 _addCoordinate(mirVec, valueTabBuf[e],
false);
1744 delete [] coordTabBuf;
1745 coordTabBuf =
nullptr;
1746 delete [] valueTabBuf;
1747 valueTabBuf =
nullptr;
1750 _calculateRealKernelExt();
1757 template <
typename KDATATYPE>
1765 if((k!=0) && (k!=n)){
1766 for (i=1; i<(n+1); i++){ v*=i; }
1767 for (i=1; i<(k+1); i++){ v/=i; }
1768 for (i=1; i<(n-k+1); i++){ v/=i; }
1781 template <
typename KDATATYPE>
1785 std::vector<KDATATYPE> v;
1787 if (numSamples > 0){
1788 v.reserve(numSamples);
1792 for (
size_t u=0; u<numSamples; ++u){
1795 KDATATYPE val =
static_cast<KDATATYPE
>(binomialcoeff(numSamples-1, u));
1797 sum +=
static_cast<KDATATYPE
>(
mlAbs(val));
1801 if (normalize && (sum > 0)){
1802 for (
size_t u=0; u<numSamples; u++){ v[u] /= sum; }
1813 template <
typename KDATATYPE>
1817 _invalidateSeparableInfos();
1823 std::vector<KDATATYPE> vx=get1DGauss(ext.
x,
false);
1824 std::vector<KDATATYPE> vy=get1DGauss(ext.
y,
false);
1825 std::vector<KDATATYPE> vz=get1DGauss(ext.
z,
false);
1826 std::vector<KDATATYPE> vc=get1DGauss(ext.
c,
false);
1827 std::vector<KDATATYPE> vt=get1DGauss(ext.
t,
false);
1828 std::vector<KDATATYPE> vu=get1DGauss(ext.
u,
false);
1832 setKernel(ext, &(vx[0]), &(vy[0]), &(vz[0]), &(vc[0]), &(vt[0]), &(vu[0]),
true);
1839 template <
typename KDATATYPE>
1848 _valueTab =
nullptr;
1849 _coordTab =
nullptr;
1852 _isSeparable =
false;
1853 _areSeparabilityInfosUpToDate =
false;
1854 _separableDimEntries.set(0);
1855 _separableOneDimExt.set(0);
1856 _separableExt.set(0);
1857 _separableNegExt.set(0);
1858 _separablePosExt.set(0);
1859 _separableCoordTab.clear();
1866 template <
typename KDATATYPE>
1873 _areSeparabilityInfosUpToDate =
false;
1875 delete [] _valueTab;
1877 _valueTab =
nullptr;
1878 delete [] _coordTab;
1879 _coordTab =
nullptr;
1889 template <
typename KDATATYPE>
1894 KDATATYPE *newValueTab =
nullptr;
1897 _areSeparabilityInfosUpToDate =
false;
1900 size_t newTabSize = _tabSize+1;
1903 newValueTab =
new KDATATYPE[_tabSize+1];
1906 if (!newCoordTab || !newValueTab){
1907 delete [] newCoordTab;
1908 newCoordTab =
nullptr;
1909 delete [] newValueTab;
1910 newValueTab =
nullptr;
1913 "Cannot create kernel tables. Returning with invalid "
1914 "reset tables. This will probably cause other errors.");
1920 memcpy(newCoordTab, _coordTab, _tabSize*
sizeof(
ImageVector));
1921 memcpy(newValueTab, _valueTab, _tabSize*
sizeof(KDATATYPE));
1925 newCoordTab[_tabSize] = pos;
1926 newValueTab[_tabSize] = value;
1932 _tabSize = newTabSize;
1933 _coordTab = newCoordTab;
1934 _valueTab = newValueTab;
1937 if (update){ _calculateRealKernelExt(); }
1947 template <
typename KDATATYPE>
1955 if (getTabSize() > 0){
1956 for (
size_t c=0; c < getTabSize(); c++){
1967 _negExt = calculateNegativeExtentFromExtent(_ext);
1968 _posExt = calculatePositiveExtentFromExtent(_ext);
1971 if (!_ext.allBiggerZero()){
1974 "Kernel has invalid extents now. Continuing anyway.");
1992 template <
typename KDATATYPE>
1996 if (_isSeparable != isSeparableVal){
1997 _isSeparable = isSeparableVal;
1998 _invalidateSeparableInfos();
2006 template <
typename KDATATYPE>
2009 return _isSeparable;
2017 template <
typename KDATATYPE>
2020 _validateSeparabilityInfos();
2021 return _separableDimEntries;
2031 template <
typename KDATATYPE>
2034 _validateSeparabilityInfos();
2035 return _separableOneDimExt;
2046 template <
typename KDATATYPE>
2049 _validateSeparabilityInfos();
2050 if (dim>5){ dim = 5; }
2056 case 1:
return static_cast<size_t>(_separableDimEntries.x);
2058 case 2:
return static_cast<size_t>(_separableDimEntries.x +
2059 _separableDimEntries.y);
2061 case 3:
return static_cast<size_t>(_separableDimEntries.x +
2062 _separableDimEntries.y +
2063 _separableDimEntries.z);
2065 case 4:
return static_cast<size_t>(_separableDimEntries.x +
2066 _separableDimEntries.y +
2067 _separableDimEntries.z +
2068 _separableDimEntries.c);
2070 case 5:
return static_cast<size_t>(_separableDimEntries.x +
2071 _separableDimEntries.y +
2072 _separableDimEntries.z +
2073 _separableDimEntries.c +
2074 _separableDimEntries.t);
2086 template <
typename KDATATYPE>
2089 _validateSeparabilityInfos();
2090 return _separableCoordTab;
2096 template <
typename KDATATYPE>
2099 _areSeparabilityInfosUpToDate =
false;
2109 template <
typename KDATATYPE>
2113 if (_areSeparabilityInfosUpToDate){
return; }
2114 if (!_areSeparabilityInfosUpToDate){
2120 _separableDimEntries.set(0);
2121 _separableOneDimExt.set(0);
2122 _separableExt.set(0);
2123 _separableCoordTab.clear();
2126 while ((idx<_tabSize) && (_coordTab[idx].y < 6)){
2130 const size_t entryY = mlrange_cast<size_t>(entry.
y);
2136 _separableDimEntries[entryY]++;
2141 if (entry.
x+1 > _separableOneDimExt[entryY]){ _separableOneDimExt[entryY] = entry.
x+1; }
2152 sepCoord[entryY] = entry.
x;
2153 _separableCoordTab.push_back(sepCoord);
2161 _separableExt = _separableOneDimExt;
2162 _separableExt.fillSmallerComps(1,1);
2170 for (
size_t e=0; e < idx; ++e){
2173 for (
size_t d=0; d < 6; ++d){
2175 if (coord[d] == -1){ coord[d] = negExt[d]; }
2185 _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 false.
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
Returns true if values differ, otherwise false.
#define ML_CALCULATION_ERROR
This is an unspecific error used in some cases where the error is not very specific; for which there ...
#define ML_PROGRAMMING_ERROR
A case occurred which should not appear and here 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 depended 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 which is used by the ML for indexing and coordinates.