From: eduardo.davila@creatis.insa-lyon.fr Date: Sun, 1 Mar 2026 13:56:43 +0000 (+0100) Subject: #3537 Bifurcations In Skeletonization X-Git-Url: http://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=4baa600e55663a3b4c855c8d5f51a60586491b2e;p=creaVtk.git #3537 Bifurcations In Skeletonization --- diff --git a/bbtk_creaVtk_PKG/.DS_Store b/bbtk_creaVtk_PKG/.DS_Store index 9e9655d..8fd3482 100644 Binary files a/bbtk_creaVtk_PKG/.DS_Store and b/bbtk_creaVtk_PKG/.DS_Store differ diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkBifurcationsInSkeletonization.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkBifurcationsInSkeletonization.cxx index 477f9e3..2a67de1 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkBifurcationsInSkeletonization.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkBifurcationsInSkeletonization.cxx @@ -15,9 +15,17 @@ BBTK_BLACK_BOX_IMPLEMENTATION(BifurcationsInSkeletonization,bbtk::AtomicBlackBox void BifurcationsInSkeletonization::Process() { printf("EED BifurcationsInSkeletonization::Process start \n"); - std::vector tmpLstX=bbGetInputLstX(); - std::vector tmpLstY=bbGetInputLstY(); - std::vector tmpLstZ=bbGetInputLstZ(); + + // ---- Step 1.1 Find start point of the segments ---- + // ---- step 1.2 Cleaning repeated start points ---- + // ---- Step 2.1 Find leaves ---- + // ---- Step 2.2 Cleaning repeated leaves ---- + // ---- Step 3.0 Find all bifurcations ---- + + + std::vector tmpLstX = bbGetInputLstX(); + std::vector tmpLstY = bbGetInputLstY(); + std::vector tmpLstZ = bbGetInputLstZ(); std::vector leavesLstX; std::vector leavesLstY; std::vector leavesLstZ; @@ -37,9 +45,14 @@ void BifurcationsInSkeletonization::Process() tmpImage->DeepCopy( bbGetInputIn() ); int px,py,pz, i,j,k, tx,ty,tz, ii,size; // Find all leaves - long int w=1; - int ww; + long int w; + long int ww; bool ok; + + + // ---- Step 1.1 Find start point of the segments----------- + + w=2; while (tmpLstX.size()!=0) { px = tmpLstX[0]; @@ -50,7 +63,7 @@ void BifurcationsInSkeletonization::Process() tmpLstZ.erase( tmpLstZ.begin() ); if (tmpImage->GetScalarComponentAsDouble(px,py,pz,0)<=1) { - w = w + 1; +// w = w + 1; tmpImage->SetScalarComponentFromDouble( px,py,pz,0, w ); ok=false; for ( i=px-1 ; i<=px+1 ; i++) @@ -63,15 +76,15 @@ void BifurcationsInSkeletonization::Process() { if ((i>=0) &&(j>=0) &&(k>=0) &&(iGetScalarComponentAsDouble(i,j,k,0)) + if ( 1 == tmpImage->GetScalarComponentAsDouble(i,j,k,0)) { ok=true; -// tmpLstX.push_back(i); -// tmpLstY.push_back(j); -// tmpLstZ.push_back(k); - tmpLstX.insert(tmpLstX.begin() , i); - tmpLstY.insert(tmpLstY.begin() , j); - tmpLstZ.insert(tmpLstZ.begin() , k); +// tmpLstX.push_back(i); +// tmpLstY.push_back(j); +// tmpLstZ.push_back(k); + tmpLstX.insert(tmpLstX.begin() , i); + tmpLstY.insert(tmpLstY.begin() , j); + tmpLstZ.insert(tmpLstZ.begin() , k); } // if graylevel == 1 } // if ijk>0 && ijk 1 + }// if value <= 1 } // while tmpLstX.size()!=0 + // ---- step 1.2 Cleaning repeated start points---- size = leavesLstX.size(); - // Cleaning repeated leaves for (i=size-1; i>=0; i--) { for (ii=size-1; ii>i; ii--) @@ -103,9 +116,185 @@ void BifurcationsInSkeletonization::Process() }// for ii } // for i + + + // ---- Step 2.1 Find leaves ----------- + tmpLstX = leavesLstX; + tmpLstY = leavesLstY; + tmpLstZ = leavesLstZ; + leavesLstX.clear(); + leavesLstY.clear(); + leavesLstZ.clear(); + w=2; + while (tmpLstX.size()!=0) + { + px = tmpLstX[0]; + py = tmpLstY[0]; + pz = tmpLstZ[0]; + tmpLstX.erase( tmpLstX.begin() ); + tmpLstY.erase( tmpLstY.begin() ); + tmpLstZ.erase( tmpLstZ.begin() ); + if (tmpImage->GetScalarComponentAsDouble(px,py,pz,0)<=2) + { + w = w + 1; + tmpImage->SetScalarComponentFromDouble( px,py,pz,0, w ); + ok=false; + for ( i=px-1 ; i<=px+1 ; i++) + { + for ( j=py-1 ; j<=py+1;j++) + { + for ( k=pz-1 ; k<=pz+1 ; k++ ) + { + if (!((px==i) && (py==j) && (pz==k))) + { + if ((i>=0) &&(j>=0) &&(k>=0) &&(iGetScalarComponentAsDouble(i,j,k,0)) + { + ok=true; +// tmpLstX.push_back(i); +// tmpLstY.push_back(j); +// tmpLstZ.push_back(k); + tmpLstX.insert(tmpLstX.begin() , i); + tmpLstY.insert(tmpLstY.begin() , j); + tmpLstZ.insert(tmpLstZ.begin() , k); + } // if graylevel == 2 + } // if ijk>0 && ijk=0; i--) + { + for (ii=size-1; ii>i; ii--) + { + if ( (leavesLstX[i]==leavesLstX[ii]) && (leavesLstY[i]==leavesLstY[ii]) && (leavesLstZ[i]==leavesLstZ[ii]) ) + { + leavesLstX.erase( leavesLstX.begin()+ii ); + leavesLstY.erase( leavesLstY.begin()+ii ); + leavesLstZ.erase( leavesLstZ.begin()+ii ); + size--; + } // if iPoint == iiPoint + }// for ii + } // for i + + + // --- Step 3.0 Find all bifurcations --- ww=-1; - double gl; - // Find all bifurcations + double gl=-1; + while (leavesLstX.size()!=0) + { + tmpLstX.clear(); + tmpLstY.clear(); + tmpLstZ.clear(); + tmpLstX.push_back( leavesLstX[0] ); + tmpLstY.push_back( leavesLstY[0] ); + tmpLstZ.push_back( leavesLstZ[0] ); + + leavesLstX.erase( leavesLstX.begin() ); + leavesLstY.erase( leavesLstY.begin() ); + leavesLstZ.erase( leavesLstZ.begin() ); + + ok = false; + while (( tmpLstX.size()!=0 ) && (ok==false)) + { + px = tmpLstX[0]; + py = tmpLstY[0]; + pz = tmpLstZ[0]; + tmpLstX.erase( tmpLstX.begin() ); + tmpLstY.erase( tmpLstY.begin() ); + tmpLstZ.erase( tmpLstZ.begin() ); + + w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); +// ok = false; +// tmpImage->SetScalarComponentFromDouble( px,py,pz,0, 0 ); + tmpImage->SetScalarComponentFromDouble( px,py,pz,0,ww); + for ( i=px-1 ; i<=px+1 ; i++ ) + { + for ( j=py-1 ; j<=py+1 ; j++ ) + { + for ( k=pz-1 ; k<=pz+1 ; k++ ) + { + if (!((px==i) && (py==j) && (pz==k))) + { + gl = tmpImage->GetScalarComponentAsDouble(i,j,k,0); + if ((gl0) ) + { + tmpLstX.push_back( i ); + tmpLstY.push_back( j ); + tmpLstZ.push_back( k ); +// tx = i; +// ty = j; +// tz = k; +// ok = true; + } // if graylevel == w + if ((gl>ww) && (gl<0)) + { + ok = true; + tx = i; + ty = j; + tz = k; + } + + } // if px,py,pz != i,j,k + } // for k + } // for j + } // for i +// px = tx; +// py = ty; +// pz = tz; + } // while tmpLstX.size && ok==true + + ww = ww -1; +// ok = false; +// w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); +// for ( i=px-2 ; i<=px+2 ; i++ ) +// { +// for ( j=py-2 ; j<=py+2 ; j++ ) +// { +// for ( k=pz-2 ; k<=pz+2 ; k++ ) +// { +// if (!((px==i) && (py==j) && (pz==k))) +// { +// gl = tmpImage->GetScalarComponentAsDouble(i,j,k,0); +// if (gl<0) +// { +// if ( abs( abs(gl)-abs(w) ) >= 2 ) +// { +// ok=true; +// } // if abs (diff w) +// } // if graylevel == w +// } // if px,py,pz != i,j,k +// } // for k +// } // for j +// } // for i + + if (ok==true) + { + outLstX.push_back( tx ); + outLstY.push_back( ty ); + outLstZ.push_back( tz ); + } + + } // while leavesLstX.size()!=0 + + + + /* + // --- Step 3.0 Find all bifurcations --- + ww=-1; + double gl=-1; while (leavesLstX.size()!=0) { px = leavesLstX[0]; @@ -114,7 +303,7 @@ void BifurcationsInSkeletonization::Process() leavesLstX.erase( leavesLstX.begin() ); leavesLstY.erase( leavesLstY.begin() ); leavesLstZ.erase( leavesLstZ.begin() ); - w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); +// w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); // printf("EED BifurcationsInSkeletonization::Process px,py,pz %d %d %d w=%ld ww=%d \n", px,py,pz, w,ww); ok = true; while ( (tmpImage->GetScalarComponentAsDouble(px,py,pz,0)!=1) && (ok==true) ) @@ -150,14 +339,48 @@ void BifurcationsInSkeletonization::Process() } // while graylevel!=1 && ok==true ww = ww -1; - outLstX.push_back( px ); - outLstY.push_back( py ); - outLstZ.push_back( pz ); + + ok = false; + w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); + for ( i=px-2 ; i<=px+2 ; i++ ) + { + for ( j=py-2 ; j<=py+2 ; j++ ) + { + for ( k=pz-2 ; k<=pz+2 ; k++ ) + { + if (!((px==i) && (py==j) && (pz==k))) + { + gl = tmpImage->GetScalarComponentAsDouble(i,j,k,0); + if (gl<0) + { + if ( abs( abs(gl)-abs(w) ) >= 2 ) + { + ok=true; + } // if abs (diff w) + } // if graylevel == w + } // if px,py,pz != i,j,k + } // for k + } // for j + } // for i + + if (ok==true) + { + outLstX.push_back( px ); + outLstY.push_back( py ); + outLstZ.push_back( pz ); + } + } // while leavesLstX.size()!=0 - - bbSetOutputOutLstX(outLstX); - bbSetOutputOutLstY(outLstY); - bbSetOutputOutLstZ(outLstZ); + + */ + bbSetOutputOutLstX(outLstX); + bbSetOutputOutLstY(outLstY); + bbSetOutputOutLstZ(outLstZ); + + //bbSetOutputOutLstX(leavesLstX); + //bbSetOutputOutLstY(leavesLstY); + //bbSetOutputOutLstZ(leavesLstZ); + bbSetOutputOut(tmpImage); } else { bbSetOutputOutLstX(outLstX);