Exemple #1
0
/* The computational routine */
void knnfield(const mwSize *dimsA, const mwSize *dimsB, nnf_data_t* videoA, nnf_data_t* videoB, NNFieldParams params, int32_t *outMatrix, nnf_data_t * distMatrix)
{
    Video<nnf_data_t> A;
    int dA[4];
    for (int i = 0; i < 4; ++i) {
        dA[i] = dimsA[i];
    }
    A.initFromMxArray(4, dA, videoA);

    Video<nnf_data_t> B;
    int dB[4];
    for (int i = 0; i < 4; ++i) {
        dB[i] = dimsB[i];
    }
    B.initFromMxArray(4, dB, videoB);

    NNField field(&A,&B, params);
    NNFieldOutput output = field.compute();
    Video<int32_t> &nnf  = output.nnf;
    Video<nnf_data_t> &cost  = output.error;

    const int32_t* pData = nnf.dataReader();
    const nnf_data_t* pCost = cost.dataReader();

    int channel_stride = nnf.voxelCount();
    int in_nn_stride   = 3*channel_stride;
    int out_nn_stride  = 3*channel_stride;


    for (unsigned int idx = 0; idx < dimsA[0]*dimsA[1]*dimsA[2]; ++idx) // each voxel
    {
        for(int k = 0; k < params.knn; ++ k) { // each NN
            for (unsigned int c = 0; c < 3; ++c) { // each warp channel
                outMatrix[idx + c*channel_stride + k*out_nn_stride] = pData[idx + c*channel_stride + k*in_nn_stride];
            }
            assert(outMatrix[idx + 0*channel_stride + k*out_nn_stride] < B.getWidth()-params.patch_size_space+1);
            assert(outMatrix[idx + 1*channel_stride + k*out_nn_stride] < B.getHeight()-params.patch_size_space+1);
            assert(outMatrix[idx + 2*channel_stride + k*out_nn_stride] < B.frameCount()-params.patch_size_time+1);
        }
    }

    if(distMatrix != nullptr) {
        for (unsigned int idx = 0; idx < dimsA[0]*dimsA[1]*dimsA[2]; ++idx) // each voxel
        {
            for(int k = 0; k < params.knn; ++ k) { // each NN
                distMatrix[idx + k*channel_stride] = pCost[idx + k*channel_stride];
            }
        }
    }
}
Exemple #2
0
/* The computational routine */
void stwarp(const mwSize *dimsA, const mwSize *dimsB, stwarp_video_t * videoA, stwarp_video_t *videoB, float *outMatrix, STWarpParams params, const float* initWarp)
{
    WarpingField<precision_t> uvw;
    STWarp<precision_t> warper = STWarp<precision_t>();

    warper.setParams(params);

    Video<stwarp_video_t> A;
    int dA[4];
    for (int i = 0; i < 4; ++i) {
        dA[i] = dimsA[i];
    }
    A.initFromMxArray(4, dA, videoA);

    Video<stwarp_video_t> B;
    int dB[4];
    for (int i = 0; i < 4; ++i) {
        dB[i] = dimsB[i];
    }
    B.initFromMxArray(4, dB, videoB);


    warper.setVideos(A,B);

    if(initWarp) {
        WarpingField<float> warp;
        int dWF[4];
        for (int i = 0; i < 3; ++i) {
            dWF[i] = dimsA[i];
        }
        dWF[3] = 3;
        warp.initFromMxArray(4, dWF, initWarp);
        warper.setInitialWarpField(warp);
    }

    uvw = warper.computeWarp();
    uvw.copyToMxArray(dimsA[0]*dimsA[1]*dimsA[2]*dimsA[3],outMatrix);
}