27 #include <Base/Debug/Debug.hh>
28 #include <Base/Debug/Error.hh>
29 #include <Base/ImageUtils/ImageDraw.hh>
30 #include <Base/Math/Matrix2x2.hh>
31 #include <Filter/GradientSobel3x3.hh>
32 #include <MathAlgo/SVD.hh>
35 #include "ContourDetectorBSpline.hh"
40 template <
class StorageType>
44 pShapeSpaceMatrix_=NULL;
45 pSubShapeSpaceMatrix_=NULL;
47 curveInitialised_=
false;
48 fitSampleWidth_=
new double(0.1);
49 drawSampleWidth_=
new double(0.1);
53 template <
class StorageType>
56 if(pData_!=NULL){pData_->Unregister();}
57 if(pShapeSpaceMatrix_!=NULL){pShapeSpaceMatrix_->Unregister();}
58 if(pSubShapeSpaceMatrix_!=NULL){pSubShapeSpaceMatrix_->Unregister();}
59 if(pRegMatrix_!=NULL){pRegMatrix_->Unregister();}
63 template <
class StorageType>
66 std::vector<BIAS::BIASContour>& contour){
68 BIASWARN(
"Unfinished!");
83 std::vector<ContourBSplineData*> bSplineData;
84 for(i=0;i<bSplines.size();i++){
85 bSplineData.push_back(bSplines[i].pData_);
91 unsigned int splinesNumBasePolynoms;
94 for(i=0;i<bSplines.size();i++){
95 splinesNumBasePolynoms=((bSplines[i]).pData_)->numBasePolynoms_;
96 for(j=0;j<splinesNumBasePolynoms;j++){
97 Q[pos+j]=((bSplines[i]).Q_)[j];
98 Q[pos+j+numBasePolynoms]=((bSplines[i]).Q_)[j+splinesNumBasePolynoms];
100 pos+=splinesNumBasePolynoms;
107 template <
class StorageType>
void
111 const std::vector<unsigned int>& mPnts,
117 Init(order, bType, mPnts, Q);
121 template <
class StorageType>
void
128 std::vector<unsigned int> mPnts(cPnts.size(),1);
133 Init(order, bType, mPnts, Q);
137 template <
class StorageType>
void
141 const std::vector<unsigned int>& mPnts,
144 TestInit_(order, bType, mPnts, Q);
147 cout<<
"test init done"<<endl;
150 cout<<
"register done"<<endl;
151 BIASCDOUT(D_CONTOURBSPLINE_INIT,
"metricmatrix: " <<
152 pData_->splineMetricMatrix_ <<
153 std::endl<<std::flush);
157 template <
class StorageType>
void
163 std::vector<unsigned int> mPnts(Q.
Size()/2,1);
165 Init(order, bType, mPnts, Q);
168 template <
class StorageType>
void
172 unsigned int numBasePolynoms = pData_->numBasePolynoms_;
173 unsigned int order = pData_->order_;
174 unsigned int numSpans = pData_->numSpans_;
179 for(i=0;i<numBasePolynoms;i++){
181 Qy[i][0]=Q_[i+numBasePolynoms];
184 curveVectors_.
clear();
187 std::vector<BIAS::Vector<double> > tmpBin(2);
191 for(i=0;i<numSpans;i++){
194 tmpMat.
MultLeft((pData_->placedSpanMatrices_)[i]);
198 tmpMat.
MultLeft((pData_->placedSpanMatrices_)[i]);
203 curveVectors_.push_back(tmpBin);
205 curveInitialised_=
true;
208 template <
class StorageType>
void
211 const double& alpha,
const unsigned int normalWidth){
213 if(!curveInitialised_){ InitCurve_(); }
217 GetFeatImage_(greyImg, featImg, normalWidth);
219 Fit_(featImg, alpha, normalWidth);
223 template <
class StorageType>
void
226 const double& alpha,
const unsigned int normalWidth,
227 const double& minClip){
229 if(!curveInitialised_){ InitCurve_(); }
233 GetFeatImage_(greyImg, featImg, normalWidth);
235 Fit_(featImg, alpha, normalWidth, minClip);
239 template <
class StorageType>
void
242 const double& alpha,
const unsigned int normalWidth){
244 if(!curveInitialised_){ InitCurve_(); }
245 Fit_(featImg, alpha, normalWidth);
249 template <
class StorageType>
void
252 const double& alpha,
const unsigned int normalWidth,
253 const double& minClip){
254 if(!curveInitialised_){ InitCurve_(); }
255 Fit_(featImg, alpha, normalWidth, minClip);
259 template <
class StorageType>
bool
261 Save(
const std::string& filename){
265 fs.open(filename.c_str(), std::ofstream::out | std::ofstream::binary);
266 if(!fs.is_open())
return false;
269 fs.write( (
char*) &(pData_->order_),
sizeof(
unsigned int) );
275 fs.write( (
char*) &(pData_->numBasePolynoms_),
sizeof(
unsigned int) );
278 for(i=0;i<(pData_->numBasePolynoms_);i++){
279 fs.write( (
char*) &((pData_->mPnts_)[i]),
sizeof(
unsigned int) );
283 for(i=0;i<2*(pData_->numBasePolynoms_);i++){
284 fs.write( (
char*) &(Q_[i]),
sizeof(
double) );
290 fs.write( (
char*) &(pData_->numSpans_),
sizeof(
unsigned int) );
293 for(i=0;i<pData_->numSpans_;i++){
294 for(j=0;j<pData_->order_;j++){
295 for(k=0;k<pData_->numBasePolynoms_;k++){
296 fs.write( (
char*) &((pData_->placedSpanMatrices_)[i][j][k]),
302 unsigned int numSpansVecSize=(pData_->numSpansVec_).size();
303 fs.write( (
char*) &numSpansVecSize,
sizeof(
unsigned int) );
306 for(i=0;i<numSpansVecSize;i++){
307 fs.write( (
char*) &((pData_->numSpansVec_)[i]),
sizeof(
unsigned int) );
317 template <
class StorageType>
bool
319 Load(
const std::string& filename){
323 fs.open(filename.c_str(), std::ifstream::in | std::ifstream::binary);
329 fs.read( (
char*) &order,
sizeof(
unsigned int) );
336 unsigned int numBasePolynoms;
337 fs.read( (
char*) &numBasePolynoms,
sizeof(
unsigned int) );
340 std::vector<unsigned int> mPnts(numBasePolynoms);
341 for(i=0; i<numBasePolynoms; i++){
342 fs.read( (
char*) &mPnts[i],
sizeof(
unsigned int) );
347 for(i=0; i<2*numBasePolynoms; i++){
348 fs.read( (
char*) &Q[i],
sizeof(
double) );
354 unsigned int numSpans;
356 fs.read( (
char*) &numSpans,
sizeof(
unsigned int) );
359 std::vector<BIAS::Matrix<double> > placedSpanMatrices;
361 for(i=0;i<numSpans;i++){
362 for(j=0;j<order;j++){
363 for(k=0;k<numBasePolynoms;k++){
364 fs.read( (
char*) &(placedSpanMatrix[j][k]),
sizeof(
double) );
367 placedSpanMatrices.push_back(placedSpanMatrix);
371 unsigned int numSpansVecSize;
372 fs.read( (
char*) &numSpansVecSize,
sizeof(
unsigned int) );
375 std::vector<unsigned int> numSpansVec(numSpansVecSize);
376 for(i=0;i<numSpansVecSize;i++){
377 fs.read( (
char*) &(numSpansVec[i]),
sizeof(
unsigned int) );
383 numSpans, numSpansVec,
388 Init(order, bType, mPnts, Q);
397 template <
class StorageType>
void
405 rot[0][0]=cos(angle);
406 rot[0][1]=-sin(angle);
407 rot[1][0]=sin(angle);
408 rot[1][1]=cos(angle);
409 for(i=0;i<pData_->numBasePolynoms_;i++){
411 tmp[1]=Q_[i+(pData_->numBasePolynoms_)];
414 Q_[i+(pData_->numBasePolynoms_)]=tmp2[1];
418 template <
class StorageType>
void
421 if(!curveInitialised_){ InitCurve_(); }
423 unsigned int numSpans= pData_->numSpans_;
437 span = (
unsigned int) (t * (
double)(numSpans));
438 s= (t*numSpans) - span;
442 GetPointAndParamVec_(span,s,sVec,res);
446 template <
class StorageType>
void
449 if(!curveInitialised_){ InitCurve_();}
452 unsigned int numSpans=pData_->numSpans_;
465 span = (
unsigned int) (t * (
double)(numSpans) );
466 s= (t*numSpans) - span;
470 GetNormal_(span,s,res);
474 template <
class StorageType>
void
478 const unsigned int normalWidth,
482 GetFeatImage_(greyImg,featImg,normalWidth);
485 GetFeature(featImg, t, normalWidth, res);
489 template <
class StorageType>
void
493 const unsigned int normalWidth,
494 const double& minClip,
498 GetFeatImage_(greyImg,featImg,normalWidth);
501 GetFeature(featImg, t, normalWidth, minClip, res);
505 template <
class StorageType>
void
509 const unsigned int normalWidth,
512 if(!curveInitialised_){ InitCurve_(); }
515 unsigned int numSpans=pData_->numSpans_;
528 span = (
unsigned int) (t * (
double)(numSpans) );
529 s= (t*numSpans) - span;
535 GetPoint_(span,s,curvePnt);
537 GetNormal_(span,s,normal);
539 GetFeature(featImg, normalWidth, curvePnt, normal, res);
543 template <
class StorageType>
void
547 const unsigned int normalWidth,
548 const double& minClip,
551 if(!curveInitialised_){ InitCurve_(); }
554 unsigned int numSpans=pData_->numSpans_;
567 span = (
unsigned int) (t * (
double)(numSpans) );
568 s= (t*numSpans) - span;
573 GetPoint_(span,s,curvePnt);
575 GetNormal_(span,s,normal);
577 GetFeature(featImg, normalWidth, curvePnt, normal, minClip, res);
581 template <
class StorageType>
void
584 int& maxX,
int& maxY){
586 unsigned int offset = Q_.size()/2;
589 minX=(int) (Q_[0]+0.5);
590 maxX=(int) (Q_[0]+0.5);
591 minY=(int) (Q_[offset]+0.5);
592 maxY=(int) (Q_[offset]+0.5);
594 for(i=1;i<offset;i++){
595 tmpX=(int) (Q_[i]+0.5);
596 tmpY=(int) (Q_[offset+i]+0.5);
600 else if(tmpX > maxX){
606 else if(tmpY > maxY){
610 BIASCDOUT(D_CONTOURBSPLINE_BOUNDINGBOX,
"BSplines Bounding Box is: (" <<
611 minX <<
"," << minY <<
") (" << maxX <<
"," << maxY <<
")." << std::endl <<
616 template <
class StorageType>
void
619 const StorageType color[3]){
623 for(i=0; i<pData_->numBasePolynoms_;i++){
626 (
unsigned int)Q_[i+pData_->numBasePolynoms_],
632 template <
class StorageType>
void
635 const StorageType color[3]){
636 if(!curveInitialised_){ InitCurve_(); }
645 double d = *drawSampleWidth_ * (double)pData_->numSpans_;
646 unsigned int offset=0;
648 for(i=0;i<(pData_->numSpansVec_).size();i++){
649 GetPoint_(offset,0.,first);
650 for(j=offset;j<((pData_->numSpansVec_)[i]+offset);j++){
651 for(t=0.;t<(1.+d);t+=d){
652 (t>1.)? GetPoint_(j,1,second):GetPoint_(j,t,second);
654 (
unsigned int)first[0],
655 (
unsigned int)first[1],
656 (
unsigned int)second[0],
657 (
unsigned int)second[1],
662 offset+=(pData_->numSpansVec_)[i];
667 template <
class StorageType>
void
670 if(!curveInitialised_){ InitCurve_(); }
674 float color[1]={255.};
680 double d = *drawSampleWidth_ * (double)pData_->numSpans_;
681 unsigned int offset=0;
683 for(i=0;i<(pData_->numSpansVec_).size();i++){
684 GetPoint_(offset,0.,first);
685 for(j=offset;j<((pData_->numSpansVec_)[i]+offset);j++){
686 for(t=0.;t<(1.+d);t+=d){
687 (t>1.)? GetPoint_(j,1,second):GetPoint_(j,t,second);
689 (
unsigned int)first[0],
690 (
unsigned int)first[1],
691 (
unsigned int)second[0],
692 (
unsigned int)second[1],
697 offset+=(pData_->numSpansVec_)[i];
702 template <
class StorageType>
void
706 const StorageType color[3]){
707 if(!curveInitialised_){ InitCurve_(); }
711 unsigned int numSpans=pData_->numSpans_;
717 double d = *fitSampleWidth_ * (double) numSpans;
719 for(i=0;i<numSpans;i++){
720 for(t=0.;t<1.+d;t+=d){
722 GetPoint_(i,1.,curvePnt);
723 GetNormal_(i,1.,normal);
725 GetPoint_(i,t,curvePnt);
726 GetNormal_(i,t,normal);
729 (
unsigned int)curvePnt[0],
730 (
unsigned int)curvePnt[1],
731 (
unsigned int)(curvePnt[0]+
732 (
double)normalWidth*normal[0]),
733 (
unsigned int)(curvePnt[1]+
734 (
double)normalWidth*normal[1]),
738 (
unsigned int) curvePnt[0],
739 (
unsigned int) curvePnt[1],
740 (
unsigned int)(curvePnt[0]-
741 (
double)normalWidth*normal[0]),
742 (
unsigned int)(curvePnt[1]-
743 (
double)normalWidth*normal[1]),
752 template <
class StorageType>
void
756 Q_.newsize(2*cPnts.size());
758 for(i=0;i<cPnts.size();i++){
760 Q_[i+cPnts.size()]=cPnts[i][1];
765 template <
class StorageType>
void
772 for(i=0;i<cPnts.size();i++){
774 Q[i+cPnts.size()]=cPnts[i][1];
779 template <
class StorageType>
void
783 cPnts.resize(Q_.size()/2);
784 for(i=0;i<cPnts.size();i++){
786 cPnts[i][1]=Q_[i+cPnts.size()];
791 template <
class StorageType>
void
796 cPnts.resize(Q.
size()/2);
797 for(i=0;i<cPnts.size();i++){
799 cPnts[i][1]=Q[i+cPnts.size()];
804 template <
class StorageType>
void
812 unsigned int order=pData_->order_;
818 resParamVec[2] = s*s;
820 for(i=3;i<order;i++){
822 for(j=0;j<(i-1);j++){
828 resPoint[0]=resParamVec.
ScalarProduct(curveVectors_[span][0]);
829 resPoint[1]=resParamVec.
ScalarProduct(curveVectors_[span][1]);
833 template <
class StorageType>
void
839 unsigned int order = pData_->order_;
847 for(i=3;i<order;i++){
849 for(j=0;j<(i-2);j++){
861 double length=res.
NormL2();
867 template <
class StorageType>
void
870 const unsigned int normalWidth,
884 if((curvePnt[0])<0 || (curvePnt[1]<0) || (curvePnt[0]>featImg.
GetWidth()) ||
888 maxInt = featImg.
PixelValue((
unsigned int)(curvePnt[0]+0.5),
889 (
unsigned int)(curvePnt[1]+0.5));
891 for(i=1;i<normalWidth; i++){
893 int x = (int)(curvePnt[0]+(
double)i*normal[0]+0.5);
894 int y = (int)(curvePnt[1]+(
double)i*normal[1]+0.5);
900 res[0]=curvePnt[0]+(double)i*normal[0];
901 res[1]=curvePnt[1]+(double)i*normal[1];
906 x = (int)(curvePnt[0]-(
double)i*normal[0]+0.5);
907 y = (int)(curvePnt[1]-(
double)i*normal[1]+0.5);
912 res[0]=curvePnt[0]-(double)i*normal[0];
913 res[1]=curvePnt[1]-(double)i*normal[1];
920 template <
class StorageType>
void
923 const unsigned int normalWidth,
926 const double& minClip,
938 if((curvePnt[0])<0 || (curvePnt[1]<0) || (curvePnt[0]>featImg.
GetWidth()) ||
942 maxInt = featImg.
PixelValue((
unsigned int)(curvePnt[0]+0.5),
943 (
unsigned int)(curvePnt[1]+0.5));
945 for(i=1;i<normalWidth; i++){
947 int x = (int)(curvePnt[0]+(
double)i*normal[0]+0.5);
948 int y = (int)(curvePnt[1]+(
double)i*normal[1]+0.5);
952 if(tmpInt>maxInt && tmpInt>=minClip){
954 res[0]=curvePnt[0]+(double)i*normal[0];
955 res[1]=curvePnt[1]+(double)i*normal[1];
960 x = (int)(curvePnt[0]-(
double)i*normal[0]+0.5);
961 y = (int)(curvePnt[1]-(
double)i*normal[1]+0.5);
964 if(tmpInt>maxInt && tmpInt>=minClip){
966 res[0]=curvePnt[0]-(double)i*normal[0];
967 res[1]=curvePnt[1]-(double)i*normal[1];
975 template <
class StorageType>
void
982 unsigned int numSpans=pData_->numSpans_;
983 unsigned int numBasePolynoms=pData_->numBasePolynoms_;
996 unsigned int size=pShapeSpaceMatrix_->num_cols();
1004 for(t=0.; t<(1.+*fitSampleWidth_); t+=*fitSampleWidth_){
1022 span = (
unsigned int) (t * (
double)(numSpans) );
1023 s= (t*(double)numSpans) - (double)span;
1025 GetPointAndParamVec_(span,s,sVec,curvePnt);
1026 GetNormal_(span,s,normal);
1027 GetFeature(featImg, normalWidth, curvePnt, normal, featPnt);
1030 double v = (featPnt-curvePnt).ScalarProduct(normal);
1037 (pData_->placedSpanMatrices_)[span].MultLeft(sVec, B);
1041 for(i=0;i<numBasePolynoms;i++){
1043 U[1][i+numBasePolynoms]=B[i];
1045 U.
Mult(*pShapeSpaceMatrix_);
1052 Z=Z+(((1./(double)fitSamples_)*v)*h);
1057 pRegMatrix_->
Multiply(alpha, regMat);
1059 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"old Q_" << Q_ << std::endl << std::flush);
1060 Q_=*pShapeSpaceMatrix_*(superS.
Invert()*Z) + Q_;
1061 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"new Q_" << Q_ << std::endl << std::flush);
1062 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"S^-: " << pRegMatrix_ << std::endl << std::flush);
1063 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"S: " << S << std::endl << std::flush);
1064 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"(S+S^-)^-1: " << superS.
Invert() << std::flush);
1065 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"Z: " << Z << std::endl << std::flush);
1068 curveInitialised_=
false;
1072 template <
class StorageType>
void
1075 const unsigned int normalWidth,
const double& minClip){
1080 unsigned int numSpans=pData_->numSpans_;
1081 unsigned int numBasePolynoms=pData_->numBasePolynoms_;
1094 unsigned int size=pShapeSpaceMatrix_->num_cols();
1102 for(t=0.; t<(1.+*fitSampleWidth_); t+=*fitSampleWidth_){
1120 span = (
unsigned int) (t * (
double)(numSpans) );
1121 s= (t*(double)numSpans) - (double)span;
1123 GetPointAndParamVec_(span,s,sVec,curvePnt);
1124 GetNormal_(span,s,normal);
1125 GetFeature(featImg, normalWidth, curvePnt, normal, minClip, featPnt);
1128 double v = (featPnt-curvePnt).ScalarProduct(normal);
1135 (pData_->placedSpanMatrices_)[span].MultLeft(sVec, B);
1139 for(i=0;i<numBasePolynoms;i++){
1141 U[1][i+numBasePolynoms]=B[i];
1143 U.
Mult(*pShapeSpaceMatrix_);
1150 Z=Z+(((1./(double)fitSamples_)*v)*h);
1155 pRegMatrix_->
Multiply(alpha, regMat);
1157 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"old Q_" << Q_ << std::endl << std::flush);
1158 Q_=*pShapeSpaceMatrix_*(superS.
Invert()*Z) + Q_;
1159 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"new Q_" << Q_ << std::endl << std::flush);
1160 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"S^-: " << pRegMatrix_ << std::endl << std::flush);
1161 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"S: " << S << std::endl << std::flush);
1162 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"(S+S^-)^-1: " << superS.
Invert() << std::flush);
1163 BIASCDOUT(D_CONTOURBSPLINE_FIT,
"Z: " << Z << std::endl << std::flush);
1166 curveInitialised_=
false;
1172 template <
class StorageType>
void
1176 const unsigned int normalWidth){
1179 int minx,miny,maxx,maxy;
1180 GetBoundingBox(minx,miny,maxx,maxy);
1186 (minx>(
int)normalWidth)? minx-normalWidth : 0,
1187 (miny>(
int)normalWidth)? miny-normalWidth : 0,
1188 ((maxx+normalWidth)<greyImg.
GetWidth())?
1189 maxx+normalWidth : (greyImg.
GetWidth()-1),
1190 ((maxy+normalWidth)<greyImg.
GetHeight())?
1191 maxy+normalWidth : (greyImg.
GetHeight()-1));
1195 gsobel.
Filter(greyImg,featX,featY,featImg);
1203 template <
class StorageType>
void
1207 const std::vector<unsigned int>& mPnts,
1212 if(mPnts.size()!=Q.
Size()/2){
1213 BIASERR(
"Dimension of control point vector and dimension of multiplicity"<<
1214 " vector for control points arent equal.\r\n");
1218 if(Q.
Size()/2<order){
1219 BIASERR(
"BSpline needs >=" << order <<
" control points, even if one "<<
1220 "of the control points has a multiplicity >1.\r\n");
1224 for(i=1;i<Q.
Size()/2;i++){
1225 if((Q[i]==Q[i-1]) && (Q[i+Q.
size()/2]==Q[i-1+Q.
size()/2])){
1226 BIASERR(
"Dont use real multiple control points. Pontrol point " << i <<
1227 " and " << i+1 <<
" are equal. This would bug the contour " <<
1228 "algorithm. Try to increase the multiplicity for the control " <<
1239 if(mPnts.front()>1 || mPnts.back()>1){
1240 BIASWARN(
"This BSpline interpolates through end points. A "<<
1241 "multiplicity for first and last control point greater 1 "<<
1242 "gets ignored.\r\n");
1245 for(i=1;i<order-1;i++){
1247 BIASERR(
"The first control point with multiplicity greater 1 may be "<<
1248 "control point "<< order-1 <<
"(begin counting with 0).\r\n");
1252 for(i=mPnts.size()-2;i>mPnts.size()-order;i--){
1254 BIASERR(
"the last control point with multiplicity greater 1 may be " <<
1255 "control point " << mPnts.size()-order <<
1256 "(begin counting with 0).\r\n");
1261 for(i=order-1;i<mPnts.size()-order;i++){
1262 if(mPnts[i]>=order){
1263 BIASERR(
"The multiplicity of control point " << i <<
1264 " (begin counting with 0) is >=" << order <<
1265 " and would thus split the B-SPline curve into parts.\r\n");
1276 for(i=0;i<mPnts.size();i++){
1277 if(mPnts[i]>=order){
1278 BIASERR(
"The multiplicity of " << i <<
"th control point is " <<
1279 ">=" << order <<
" and would thus split the BSpline into " <<
1296 #ifdef BUILD_IMAGE_INT
1299 #ifdef BUILD_IMAGE_CHAR
1302 #ifdef BUILD_IMAGE_SHORT
1304 #ifdef BUILD_IMAGE_USHORT
1307 #ifdef BUILD_IMAGE_UINT
1309 #ifdef BUILD_IMAGE_DOUBLE
T ScalarProduct(const Vector< T > &argvec) const
scalar product (inner product) of two vectors returning a scalr
void InitCurve_()
initializes curve for drawing or for getting points on it
void GetFeature(BIAS::Image< StorageType > &greyImg, const double &t, const unsigned int normalWidth, BIAS::Vector2< double > &res)
returns the feature point with highest gradient along the normal in curve point located at "t" ...
void GetNormal(const double &t, BIAS::Vector2< double > &res)
returns normal in curve point
void GetFeatImage_(BIAS::Image< StorageType > &greyImg, BIAS::Image< float > &featImg, const unsigned int normalWidth)
converts given grey image to gradient image with ROI
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
void GetPoint(const double &t, BIAS::Vector2< double > &res)
returns point on the curve
ContourBSplineData * pData_
pointer to data of B-Spline curve initialised by call of Init(...)
bool Load(const std::string &filename)
load/initialise a ContourBSpline object from an given binary file
Vector< T > GetCol(const int &col) const
return a copy of column "col", zero based counting
static int CircleCenterFilled(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[])
draws a filled circle using Value
void Mult(const Vector2< T > &argvec, Vector2< T > &destvec) const
matrix - vector multiplicate this matrix with Vector2, storing the result in destvec calculates: dest...
gradient calculation with sobel 3 by 3 masks
unsigned int Size() const
length of the vector
void GetPointAndParamVec_(const unsigned int numSpan, const double &s, BIAS::Vector< double > &resParamVec, BIAS::Vector2< double > &res)
computes a point on curve and a parameter vector (byproduct) which can be used for computing a specia...
unsigned int GetWidth() const
void SetZero()
equivalent to matrix call
StorageType PixelValue(const unsigned int x, const unsigned int y, const unsigned short int channel=0) const
Returns value of pixel at specific position, using specific channel as offset.
void DrawCurve(BIAS::Image< StorageType > &img, const StorageType color[3])
draws B-Spline curve into image
unsigned int numBasePolynoms_
number of base polynoms of curve - equal to number of control points
void Init(const unsigned int order, const ContourBSplineType::Type bType, const std::vector< BIAS::Vector2< double > > &cPnts)
initialisation function for simple curve without edges
void DrawControlPoints(BIAS::Image< StorageType > &img, const StorageType color[3])
draws the control points of the B-Spline curve into image
virtual void clear()
stl conform interface destroys Matrix JW
int Detect(Image< StorageType > &image, std::vector< BIAS::BIASContour > &contour)
detect function, unfinished
Vector< T > & newsize(Subscript N)
void GetNormal_(const unsigned int numSpan, const double &s, BIAS::Vector2< double > &res)
computes a normal at curve point which is parametrized by "numSpan" and "s"
BIAS::Vector< double > Q_
vector of control points; first entries are x-coordinates; last entries are y-coordinates ...
static ContourBSplineData * Register(const unsigned int order, const ContourBSplineType::Type bType, const std::vector< unsigned int > &mPnts)
registers a ContourBSpline object and returns pointer to its data object
Matrix< T > OuterProduct(const Vector< T > &v) const
outer product, constructs a matrix.
void SetZero()
Sets all values to zero.
static int Line(Image< StorageType > &im, const unsigned int start[2], const unsigned int end[2], const StorageType value[])
lines
void Rotate(const double &angle)
rotates curve by angle (rad)
ContourDetectorBSpline()
standard constructor
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
void QToCPnts_(std::vector< BIAS::Vector2< double > > &cPnts)
converts a flat control point vector Q whose first entries are x-coordinates and last entries are y-c...
unsigned int GetHeight() const
void FillImageWithConstValue(StorageType Value)
fill grey images
The image template class for specific storage types.
represents a special B-Spline and holds functions to handle fitting
void TestInit_(const unsigned int order, const ContourBSplineType::Type bType, const std::vector< unsigned int > &mPnts, const BIAS::Vector< double > &Q)
tests if B-Spline curve with given parameter can get initialized.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
void Mult(const Matrix< T > &arg, Matrix< T > &result) const
matrix multiplication, result is not allocated
void CPntsToQ_(const std::vector< BIAS::Vector2< double > > &cPnts)
converts a given control point vector in x,y-coordinates to the internal used flat control point vect...
void Fit_(const BIAS::Image< float > &featImg, const double &alpha, const unsigned int normalWidth)
fits the curve to a features curve with regularized fitting
double NormL2() const
Return the L2 norm: sqrt(a^2 + b^2)
Matrix< double > Invert()
returns pseudoinverse of A = U * S * V^T A^+ = V * S^+ * U^T
bool Save(const std::string &filename)
saves all values which are needed to reinitialise the object to a binary file
void Multiply(const T &scalar, Matrix< T > &dest) const
multiplication function, storing data destination matrix
void GetBoundingBox(int &minX, int &minY, int &maxX, int &maxY)
returns the parameter of the bounding box of the curve
void MultLeft(const Matrix< T > &arg)
in Place matrix multiplication this is equal to M = arg*M, but faster
void Fit(BIAS::Image< StorageType > &greyImg, const double &alpha, const unsigned int normalWidth)
fits B-Spline curve to gradient features found in the image
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &grad)
returns a 2 channel image containing gx and gy
static ContourDetectorBSpline Cluster(const std::vector< ContourDetectorBSpline< StorageType > > &bSplines)
builds a new ContourBspline object from given vector of ContourBSpline objects
int SetROICorners(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
void DrawNormals(const unsigned int normalWidth, BIAS::Image< StorageType > &img, const StorageType color[3])
draws B-Spline normals into image
void UnsetROI()
deprecated, use GetROI()->UnsetROI()
virtual ~ContourDetectorBSpline()
destructor