我正在做一个弥散 MRI 项目,遇到一个需要帮助的 c++ 问题。
背景:我有一个 .nii 图像作为参考,我希望控制节点(它是样条曲线的一部分)在图像的受限 ROI 内执行随机游走。澄清一下:.nii 图像是显示大脑白质 (WM) 的蒙版,我想要一个具有 4 个控制节点的样条曲线在此蒙版内随机移动,直到它们达到最小化成本函数的状态。目前我正在做的只是更新一个随机控制节点以根据高斯分布在随机方向上移动,然后检查它是在 WM 内部还是外部,如果在 WM 之外则重新绘制。但这可能会导致许多我想避免的不必要的平局。
我的问题:有没有更好的方法来做到这一点?我有一个想法,将我的 ROI 的所有像素坐标收集到一个单独的数组或矩阵中,我可以从该矩阵的索引中绘制出来?如果我想用四个全新的控制点重新初始化我的样条线,这种方法也会很有帮助。(我以后也需要实现)
当前使用方法的代码:
blitz::Array<Catmull,1> FIBERs; // Fiber with control nodes (knots) which I want to move
NIFTI<INT16>* niiWM = new NIFTI<INT16>; // .nii Image which contains WM mask
void SimulatedAnnealing_OneStep( void )
{
iF = floor( FIBERs.extent(0)*uniformGen.random()); // select randomly a FIBER
NewProposal(iF);
Pen = CheckWM(iF);
while(Pen >= 1){
NewProposal(iF);
Pen = CheckWM(iF);
}
}
void NewProposal( int ifff)
{
static int iK;
static POINT delta;
delta.Set( MOVE_sigma*normalGen.random(), MOVE_sigma*normalGen.random(), 0 );
iK = floor(uniformGen.random()*6);
if( iK==2 || iK==3 ) // Moving the middle control points within the WM
{ // FIBERs(ifff) is a randomly selected fiber (outside this method) which we are moving
FIBERs(ifff).KNOTs[iK].x += delta.x;
FIBERs(ifff).KNOTs[iK].y += delta.y;
FIBERs(ifff).KNOTs[iK].z += delta.z;
FIBERs(ifff).KNOTs[iK].x = fmin( fmax( FIBERs(ifff).KNOTs[iK].x,0), Nx );
FIBERs(ifff).KNOTs[iK].y = fmin( fmax( FIBERs(ifff).KNOTs[iK].y, 0), Ny );
FIBERs(ifff).KNOTs[iK].z = fmin( fmax( FIBERs(ifff).KNOTs[iK].z, 0), Nz );
}
}
int CheckWM( int iff )
{
int j,Pe;
int Vx, Vy, Vz;
Pe = 0;
for(j=0; j<FIBERs(iff).P.extent(0) ;j++){ // Loop through the segments on the curve
Vx = floor( FIBERs(iff).P(j).x ); // midpoint of the segment
Vy = floor( FIBERs(iff).P(j).y );
Vz = floor( FIBERs(iff).P(j).z );
if ((*niiWM->img)(Vx,Vy,Vz) == 0){ // Penalize when outside the WM
Pe += 1;}
}
return Pe;
}
我希望这是足够的信息。谢谢你的时间。