コード例 #1
0
ファイル: dynamic.cpp プロジェクト: gkocevar/mrtrix3
      Dynamic::~Dynamic()
      {

        INFO ("Dynamic seeeding required " + str (total_samples) + " samples to draw " + str (total_seeds) + " seeds");

#ifdef DYNAMIC_SEED_DEBUGGING
        const double final_mu = mu();

        // Output seeding probabilites at end of execution
        Image::Header H;
        H.info() = info();
        H.datatype() = DataType::Float32;
        Image::Buffer<float> prob_mean_data ("seed_prob_mean.mif", H), prob_sum_data ("seed_prob_sum.mif", H);
        Image::Buffer<float>::voxel_type prob_mean (prob_mean_data), prob_sum (prob_sum_data);
        VoxelAccessor v (accessor);
        Image::Loop loop;
        for (loop.start (v, prob_mean, prob_sum); loop.ok(); loop.next (v, prob_mean, prob_sum)) {
          if (v.value()) {

            float sum = 0.0;
            size_t count = 0;
            for (Fixel_map<Fixel_TD_seed>::ConstIterator i = begin (v); i; ++i) {
              sum += i().get_seed_prob (final_mu);
              ++count;
            }
            prob_mean.value() = sum / float(count);
            prob_sum .value() = sum;

          }
        }
#endif

      }
コード例 #2
0
ファイル: mrpad.cpp プロジェクト: JohnWangDataAnalyst/mrtrix3
void run ()
{

  Image::Header input_header (argument[0]);
  Image::Buffer<float> input_data (input_header);
  auto input_voxel = input_data.voxel();

  int bounds[3][2] = { {0, input_header.dim (0) - 1},
                       {0, input_header.dim (1) - 1},
                       {0, input_header.dim (2) - 1} };

  int padding[3][2] = { {0, 0}, {0, 0}, {0, 0} };

  Options opt = get_options ("uniform");
  if (opt.size()) {
    int pad = opt[0][0];
    for (int axis = 0; axis < 3; axis++) {
      padding[axis][0] = pad;
      padding[axis][1] = pad;
    }
  }

  opt = get_options ("axis");
  for (size_t i = 0; i != opt.size(); ++i) {
    // Manual padding of axis overrides uniform padding
    const int axis  = opt[i][0];
    padding[axis][0] = opt[i][1];
    padding[axis][1] = opt[i][2];
  }

  Image::Header output_header (input_header);
  Math::Matrix<float> output_transform (input_header.transform());
  for (int axis = 0; axis < 3; ++axis) {
    output_header.dim (axis) = output_header.dim(axis) + padding[axis][0] + padding[axis][1];
    output_transform (axis, 3) +=	(output_transform (axis, 0) * (bounds[0][0] - padding[0][0]) * input_header.vox (0))
                                + (output_transform (axis, 1) * (bounds[1][0] - padding[0][0]) * input_header.vox (1))
                                + (output_transform (axis, 2) * (bounds[2][0] - padding[0][0]) * input_header.vox (2));
  }
  output_header.transform() = output_transform;
  Image::Buffer<float> output_data (argument[1], output_header);
  auto output_voxel = output_data.voxel();

  Image::Loop loop ("padding image...");
  for (loop.start (output_voxel); loop.ok(); loop.next (output_voxel)) {
    bool in_bounds = true;
    for (int axis = 0; axis < 3; ++axis) {
      input_voxel[axis] = output_voxel[axis] - padding[axis][0];
      if (input_voxel[axis] < 0 || input_voxel[axis] >= input_header.dim (axis))
        in_bounds = false;
    }
    if (input_voxel.ndim() > 3)
      input_voxel[3] = output_voxel[3];
    if (in_bounds)
      output_voxel.value() = input_voxel.value();
    else
      output_voxel.value() = 0;
  }

}