• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ image::Header类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中image::Header的典型用法代码示例。如果您正苦于以下问题:C++ Header类的具体用法?C++ Header怎么用?C++ Header使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Header类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ret

 static Image::Header param (const Image::Header& header, size_t nvols) {
   Image::Header ret (header);
   ret.datatype() = DataType::Float32;
   if (nvols) ret.dim(3) = nvols;
   else ret.set_ndim (3);
   return ret;
 }
开发者ID:JohnWangDataAnalyst,项目名称:mrtrix3,代码行数:7,代码来源:tensor2metric.cpp


示例2: v

      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

      }
开发者ID:gkocevar,项目名称:mrtrix3,代码行数:33,代码来源:dynamic.cpp


示例3: run

void run ()
{
  Image::Buffer<float> dir_buf (argument[0]);
  Image::Buffer<float>::voxel_type dir_vox (dir_buf);

  Image::Header header (argument[0]);
  header.dim(3) = header.dim(3)/3;

  Image::Buffer<float> amp_buf (argument[1], header);
  Image::Buffer<float>::voxel_type amp_vox (amp_buf);

  Image::LoopInOrder loop (dir_vox, "converting directions to amplitudes...", 0, 3);

  for (loop.start (dir_vox, amp_vox); loop.ok(); loop.next (dir_vox, amp_vox)) {
    Math::Vector<float> dir (3);
    dir_vox[3] = 0;
    amp_vox[3] = 0;
    while (dir_vox[3] < dir_vox.dim(3)) {
      dir[0] = dir_vox.value(); ++dir_vox[3];
      dir[1] = dir_vox.value(); ++dir_vox[3];
      dir[2] = dir_vox.value(); ++dir_vox[3];

      float amplitude = 0.0;
      if (std::isfinite (dir[0]) && std::isfinite (dir[1]) && std::isfinite (dir[2]))
        amplitude = Math::norm (dir);

      amp_vox.value() = amplitude;
      ++amp_vox[3];
    }
  }
}
开发者ID:gkocevar,项目名称:mrtrix3,代码行数:31,代码来源:peaks2amp.cpp


示例4: print_comments

void print_comments (const Image::Header& header)
{
  std::string buffer;
  for (std::vector<std::string>::const_iterator i = header.comments().begin(); i != header.comments().end(); ++i)
    buffer += *i + "\n";
  std::cout << buffer;
}
开发者ID:szho42,项目名称:mrtrix3,代码行数:7,代码来源:mrinfo.cpp


示例5: run

void run () {

  Image::BufferPreload<bool> input_data (argument[0]);
  Image::BufferPreload<bool>::voxel_type input_voxel (input_data);

  const size_t filter_index = argument[1];

  Image::Filter::Base* filter = NULL;
  switch (filter_index) {
    case 0: filter = create_dilate_filter (input_voxel); break;
    case 1: filter = create_erode_filter  (input_voxel); break;
    case 2: filter = create_lcc_filter    (input_voxel); break;
    case 3: filter = create_median_filter (input_voxel); break;
    default: assert (0);
  }

  Image::Header header;
  header.info() = filter->info();
  Image::Stride::set_from_command_line (header);

  Image::Buffer<bool> output_data (argument[2], header);
  Image::Buffer<bool>::voxel_type output_voxel (output_data);

  filter->set_message (std::string("applying ") + std::string(argument[1]) + " filter to image " + std::string(argument[0]) + "... ");

  switch (filter_index) {
    case 0: (*dynamic_cast<Image::Filter::Dilate*>                    (filter)) (input_voxel, output_voxel); break;
    case 1: (*dynamic_cast<Image::Filter::Erode*>                     (filter)) (input_voxel, output_voxel); break;
    case 2: (*dynamic_cast<Image::Filter::LargestConnectedComponent*> (filter)) (input_voxel, output_voxel); break;
    case 3: (*dynamic_cast<Image::Filter::Median*>                    (filter)) (input_voxel, output_voxel); break;
  }

  delete filter;

}
开发者ID:gkocevar,项目名称:mrtrix3,代码行数:35,代码来源:maskfilter.cpp


示例6: print_properties

void print_properties (const Image::Header& header)
{
  std::string buffer;
  for (std::map<std::string, std::string>::const_iterator i = header.begin(); i != header.end(); ++i)
    buffer += i->first + ": " + i->second + "\n";
  std::cout << buffer;
}
开发者ID:szho42,项目名称:mrtrix3,代码行数:7,代码来源:mrinfo.cpp


示例7: print_vox

void print_vox (const Image::Header& header)
{
  std::string buffer;
  for (size_t i = 0; i < header.ndim(); ++i) {
    if (i) buffer += " ";
    buffer += str (header.vox (i));
  }
  std::cout << buffer << "\n";
}
开发者ID:szho42,项目名称:mrtrix3,代码行数:9,代码来源:mrinfo.cpp


示例8: print_strides

void print_strides (const Image::Header& header)
{
  std::string buffer;
  std::vector<ssize_t> strides (Image::Stride::get (header));
  Image::Stride::symbolise (strides);
  for (size_t i = 0; i < header.ndim(); ++i) {
    if (i) buffer += " ";
    buffer += header.stride (i) ? str (strides[i]) : "?";
  }
  std::cout << buffer << "\n";
}
开发者ID:szho42,项目名称:mrtrix3,代码行数:11,代码来源:mrinfo.cpp


示例9: T

inline Point<> get_bounds (const Image::Header& header, Point<int> corner, int axis, const Point<>& ref, const Point<>& d1, const Point<>& d2) {
  const Math::Matrix<float>& T (header.transform());
  Point<> pos (T(0,3), T(1,3), T(2,3));
  for (size_t n = 0; n < 3; ++n) 
    if (corner[n]) 
      pos += header.dim(n) * header.vox(n) * Point<> (T(0,n), T(1,n), T(2,n));
  Point<> dir (T(0,axis), T(1,axis), T(2,axis));
  Point<> ret = get_bounds (pos, dir, ref, d1, d2);
  ret[2] /= -header.vox (axis) * header.dim (axis);
  return ret;
}
开发者ID:szho42,项目名称:mrtrix3,代码行数:11,代码来源:gen_planar_ROI.cpp


示例10: run

void run ()
{
  conv_t conversion = NONE;
  Options opt = get_options ("convert");
  if (opt.size()) {
    switch (int(opt[0][0])) {
      case 0: conversion = OLD; break;
      case 1: conversion = NEW; break;
      case 2:
#ifndef USE_NON_ORTHONORMAL_SH_BASIS
        conversion = NEW;
#else
        conversion = OLD;
#endif
        break;
      case 3: conversion = FORCE_OLDTONEW; break;
      case 4: conversion = FORCE_NEWTOOLD; break;
      default: assert (0); break;
    }
  }

  for (std::vector<ParsedArgument>::const_iterator i = argument.begin(); i != argument.end(); ++i) {

    const std::string path = *i;
    Image::Header H (path);
    if (H.ndim() != 4) {
      WARN ("Image \"" + H.name() + "\" is not 4D and therefore cannot be an SH image");
      continue;
    }
    const size_t lmax = Math::SH::LforN (H.dim(3));
    if (!lmax) {
      WARN ("Image \"" + H.name() + "\" does not contain enough volumes to be an SH image");
      continue;
    }
    if (Math::SH::NforL (lmax) != size_t(H.dim(3))) {
      WARN ("Image \"" + H.name() + "\" does not contain a number of volumes appropriate for an SH image");
      continue;
    }
    if (!H.datatype().is_floating_point()) {
      WARN ("Image \"" + H.name() + "\" does not use a floating-point data type and therefore cannot be an SH image");
      continue;
    }

    if (H.datatype().bytes() == 4)
      check_and_update<float>  (H, conversion);
    else
      check_and_update<double> (H, conversion);

  }

};
开发者ID:szho42,项目名称:mrtrix3,代码行数:51,代码来源:shbasis.cpp


示例11: run

void run ()
{
  Image::Header header (argument[0]);

  header.datatype() = DataType::Float32;
  header.set_ndim (4);
  header.dim(3) = 3;
  Image::Stride::set (header, Image::Stride::contiguous_along_axis (3));

  Image::Buffer<float> warp_buffer (argument[1], header);

  Image::ThreadedLoop ("initialising warp image...", warp_buffer, 0, 3)
    .run (write_coordinates (warp_buffer), warp_buffer.voxel());
}
开发者ID:JohnWangDataAnalyst,项目名称:mrtrix3,代码行数:14,代码来源:warpinit.cpp


示例12: oversample_header

        void oversample_header (Image::Header& header, const std::vector<float>& voxel_size)
        {
          INFO ("oversampling header...");

          Math::Matrix<float> transform (header.transform());
          for (size_t j = 0; j != 3; ++j) {
            for (size_t i = 0; i < 3; ++i)
              header.transform()(i,3) += 0.5 * (voxel_size[j] - header.vox(j)) * transform(i,j);
            header.dim(j) = std::ceil(header.dim(j) * header.vox(j) / voxel_size[j]);
            header.vox(j) = voxel_size[j];
          }
        }
开发者ID:JohnWangDataAnalyst,项目名称:mrtrix3,代码行数:12,代码来源:mapping.cpp


示例13: run

void run ()
{
  Image::Header input_header (argument[0]);
  Image::Buffer<bool> input_data (input_header);
  Image::Buffer<bool>::voxel_type input_voxel (input_data);

  Image::Filter::ConnectedComponents connected_filter(input_voxel);
  Image::Header header (input_data);
  header.info() = connected_filter.info();
  Image::Buffer<int> output_data (argument[1], header);
  Image::Buffer<int>::voxel_type output_vox (output_data);

  Options opt = get_options ("axes");
  std::vector<int> axes;
  if (opt.size()) {
    axes = opt[0][0];
    for (size_t d = 0; d < input_data.ndim(); d++)
      connected_filter.set_ignore_dim (d, true);
    for (size_t i = 0; i < axes.size(); i++) {
      if (axes[i] >= static_cast<int> (input_header.ndim()) || axes[i] < 0)
        throw Exception ("axis supplied to option -ignore is out of bounds");
      connected_filter.set_ignore_dim (axes[i], false);
    }
  }

  opt = get_options ("largest");
  if (opt.size())
    connected_filter.set_largest_only (true);

  opt = get_options ("connectivity");
  if (opt.size())
    connected_filter.set_26_connectivity(true);

  connected_filter.set_message ("computing connected components...");
  connected_filter (input_voxel, output_vox);
}
开发者ID:szho42,项目名称:mrtrix3,代码行数:36,代码来源:mrconnect.cpp


示例14: H

 Segmented_FOD_receiver (const Image::Header& header, const DWI::Directions::Set& directions) :
   H (header),
   H_fixel (header),
   dirs (directions),
   lmax (0)
 {
   // aPSF does not have data for lmax > 10
   lmax = std::min (size_t(10), Math::SH::LforN (header.dim(3)));
   H.set_ndim (3);
   H.DW_scheme().clear();
   H_fixel.set_ndim (3);
   H_fixel.DW_scheme().clear();
   H_fixel.datatype() = DataType::UInt64;
   H_fixel.datatype().set_byte_order_native();
   H_fixel[Image::Sparse::name_key] = str(typeid(FixelMetric).name());
   H_fixel[Image::Sparse::size_key] = str(sizeof(FixelMetric));
 }
开发者ID:gkocevar,项目名称:mrtrix3,代码行数:17,代码来源:fod2metric.cpp


示例15: generate_header

        void generate_header (Image::Header& header, const std::string& tck_file_path, const std::vector<float>& voxel_size)
        {

          Tractography::Properties properties;
          Tractography::Reader<float> file (tck_file_path, properties);

          Streamline<float> tck;
          size_t track_counter = 0;

          Point<float> min_values ( INFINITY,  INFINITY,  INFINITY);
          Point<float> max_values (-INFINITY, -INFINITY, -INFINITY);

          {
            ProgressBar progress ("creating new template image...", 0);
            while (file (tck) && track_counter++ < MAX_TRACKS_READ_FOR_HEADER) {
              for (std::vector<Point<float> >::const_iterator i = tck.begin(); i != tck.end(); ++i) {
                min_values[0] = std::min (min_values[0], (*i)[0]);
                max_values[0] = std::max (max_values[0], (*i)[0]);
                min_values[1] = std::min (min_values[1], (*i)[1]);
                max_values[1] = std::max (max_values[1], (*i)[1]);
                min_values[2] = std::min (min_values[2], (*i)[2]);
                max_values[2] = std::max (max_values[2], (*i)[2]);
              }
              ++progress;
            }
          }

          min_values -= Point<float> (3.0*voxel_size[0], 3.0*voxel_size[1], 3.0*voxel_size[2]);
          max_values += Point<float> (3.0*voxel_size[0], 3.0*voxel_size[1], 3.0*voxel_size[2]);

          header.name() = "tckmap image header";
          header.set_ndim (3);

          for (size_t i = 0; i != 3; ++i) {
            header.dim(i) = std::ceil((max_values[i] - min_values[i]) / voxel_size[i]);
            header.vox(i) = voxel_size[i];
            header.stride(i) = i+1;
            //header.set_units (i, Image::Axis::millimeters);
          }

          //header.set_description (0, Image::Axis::left_to_right);
          //header.set_description (1, Image::Axis::posterior_to_anterior);
          //header.set_description (2, Image::Axis::inferior_to_superior);

          Math::Matrix<float>& M (header.transform());
          M.allocate (4,4);
          M.identity();
          M(0,3) = min_values[0];
          M(1,3) = min_values[1];
          M(2,3) = min_values[2];
          file.close();
        }
开发者ID:JohnWangDataAnalyst,项目名称:mrtrix3,代码行数:52,代码来源:mapping.cpp


示例16: run

void run ()
{

  Image::Buffer<node_t> nodes_data (argument[0]);
  Image::Buffer<node_t>::voxel_type nodes (nodes_data);

  Node_map node_map;
  load_lookup_table (node_map);

  Options opt = get_options ("config");
  if (opt.size()) {

    if (node_map.empty())
      throw Exception ("Cannot properly interpret connectome config file if no lookup table is provided");

    ConfigInvLookup config;
    load_config (opt[0][0], config);

    // Now that we know the configuration, can convert the lookup table to reflect the new indices
    // If no corresponding entry exists in the config file, then the node doesn't get coloured
    Node_map new_node_map;
    for (Node_map::iterator i = node_map.begin(); i != node_map.end(); ++i) {
      ConfigInvLookup::const_iterator existing = config.find (i->second.get_name());
      if (existing != config.end())
        new_node_map.insert (std::make_pair (existing->second, i->second));
    }

    if (new_node_map.empty())
      throw Exception ("Config file and parcellation lookup table do not appear to belong to one another");
    new_node_map.insert (std::make_pair (0, Node_info ("Unknown", Point<uint8_t> (0, 0, 0), 0)));
    node_map = new_node_map;

  }


  if (node_map.empty()) {

    INFO ("No lookup table provided; colouring nodes randomly");

    node_t max_index = 0;
    Image::LoopInOrder loop (nodes);
    for (loop.start (nodes); loop.ok(); loop.next (nodes)) {
      const node_t index = nodes.value();
      if (index > max_index)
        max_index = index;
    }

    node_map.insert (std::make_pair (0, Node_info ("None", 0, 0, 0, 0)));
    Math::RNG rng;

    for (node_t i = 1; i <= max_index; ++i) {
      Point<uint8_t> colour;
      do {
        colour[0] = rng.uniform_int (255);
        colour[1] = rng.uniform_int (255);
        colour[2] = rng.uniform_int (255);
      } while (int(colour[0]) + int(colour[1]) + int(colour[2]) < 100);
      node_map.insert (std::make_pair (i, Node_info (str(i), colour)));
    }

  }


  Image::Header H;
  H.info() = nodes_data.info();
  H.set_ndim (4);
  H.dim(3) = 3;
  H.datatype() = DataType::UInt8;
  H.comments().push_back ("Coloured parcellation image generated by label2colour");

  Image::Buffer<uint8_t> out_data (argument[1], H);
  Image::Buffer<uint8_t>::voxel_type out (out_data);

  Image::LoopInOrder loop (nodes, "Colourizing parcellated node image... ");
  for (loop.start (nodes, out); loop.ok(); loop.next (nodes, out)) {
    const node_t index = nodes.value();
    Node_map::const_iterator i = node_map.find (index);
    if (i == node_map.end()) {
      out[3] = 0; out.value() = 0;
      out[3] = 1; out.value() = 0;
      out[3] = 2; out.value() = 0;
    } else {
      const Point<uint8_t>& colour (i->second.get_colour());
      out[3] = 0; out.value() = colour[0];
      out[3] = 1; out.value() = colour[1];
      out[3] = 2; out.value() = colour[2];
    }
  }

}
开发者ID:szho42,项目名称:mrtrix3,代码行数:90,代码来源:label2colour.cpp


示例17: run

void run ()
{
  if (get_options ("norealign").size())
    Image::Header::do_not_realign_transform = true;

  const bool format     = get_options("format")        .size();
  const bool ndim       = get_options("ndim")          .size();
  const bool dimensions = get_options("dimensions")    .size();
  const bool vox        = get_options("vox")           .size();
  const bool dt_long    = get_options("datatype_long") .size();
  const bool dt_short   = get_options("datatype_short").size();
  const bool stride     = get_options("stride")        .size();
  const bool offset     = get_options("offset")        .size();
  const bool multiplier = get_options("multiplier")    .size();
  const bool comments   = get_options("comments")      .size();
  const bool properties = get_options("properties")    .size();
  const bool transform  = get_options("transform")     .size();
  const bool dwgrad     = get_options("dwgrad")        .size();

  Options opt = get_options ("export_grad_mrtrix");
  const std::string dw_out_mrtrix = opt.size() ? opt[0][0] : std::string();
  opt = get_options ("export_grad_fsl");
  std::string dw_out_fsl_bvecs, dw_out_fsl_bvals;
  if (opt.size()) {
    dw_out_fsl_bvecs = str(opt[0][0]);
    dw_out_fsl_bvals = str(opt[0][1]);
  }

  if ((dw_out_mrtrix.size() || dw_out_fsl_bvecs.size()) && (argument.size() > 1))
    throw Exception ("Can only export gradient table information to file if a single input image is provided");

  const bool print_full_header = (!(format || ndim || dimensions || vox || dt_long || dt_short || stride
                                  || offset || multiplier || comments || properties || transform || dwgrad)
                                  && dw_out_mrtrix.empty() && dw_out_fsl_bvecs.empty());


  for (size_t i = 0; i < argument.size(); ++i) {
    Image::Header header (argument[i]);

    if (format)     std::cout << header.format() << "\n";
    if (ndim)       std::cout << header.ndim() << "\n";
    if (dimensions) print_dimensions (header);
    if (vox)        print_vox (header);
    if (dt_long)    std::cout << (header.datatype().description() ? header.datatype().description() : "invalid") << "\n";
    if (dt_short)   std::cout << (header.datatype().specifier() ? header.datatype().specifier() : "invalid") << "\n";
    if (stride)     print_strides (header);
    if (offset)     std::cout << header.intensity_offset() << "\n";
    if (multiplier) std::cout << header.intensity_scale() << "\n";
    if (comments)   print_comments (header);
    if (properties) print_properties (header);
    if (transform)  std::cout << header.transform();
    if (dwgrad)     std::cout << header.DW_scheme();

    if (dw_out_mrtrix.size()) {
      if (!header.DW_scheme().is_set())
        throw Exception ("no gradient information found within image \"" + header.name() + "\"");
      header.DW_scheme().save (dw_out_mrtrix);
    }

    if (dw_out_fsl_bvecs.size()) {
      if (!header.DW_scheme().is_set())
        throw Exception ("no gradient information found within image \"" + header.name() + "\"");
      DWI::save_bvecs_bvals (header, dw_out_fsl_bvecs, dw_out_fsl_bvals);
    }

    if (print_full_header)
      std::cout << header.description();
  }

}
开发者ID:szho42,项目名称:mrtrix3,代码行数:70,代码来源:mrinfo.cpp


示例18: run

void run ()
{
    Image::Buffer<value_type> SH_data (argument[0]);
    Math::SH::check (SH_data);

    Options opt = get_options ("mask");

    std::unique_ptr<Image::Buffer<bool> > mask_data;
    if (opt.size())
        mask_data.reset (new Image::Buffer<bool> (opt[0][0]));

    opt = get_options ("seeds");
    Math::Matrix<value_type> dirs;
    if (opt.size())
        dirs.load (opt[0][0]);
    else {
        dirs.allocate (60,2);
        dirs = Math::Matrix<value_type> (default_directions, 60, 2);
    }
    if (dirs.columns() != 2)
        throw Exception ("expecting 2 columns for search directions matrix");

    opt = get_options ("num");
    int npeaks = opt.size() ? opt[0][0] : 3;

    opt = get_options ("direction");
    std::vector<Direction> true_peaks;
    for (size_t n = 0; n < opt.size(); ++n) {
        Direction p (Math::pi*to<float> (opt[n][0]) /180.0, Math::pi*float (opt[n][1]) /180.0);
        true_peaks.push_back (p);
    }
    if (true_peaks.size())
        npeaks = true_peaks.size();

    opt = get_options ("threshold");
    value_type threshold = -INFINITY;
    if (opt.size())
        threshold = opt[0][0];

    Image::Header header (SH_data);
    header.datatype() = DataType::Float32;

    opt = get_options ("peaks");
    std::unique_ptr<Image::Buffer<value_type> > ipeaks_data;
    if (opt.size()) {
        if (true_peaks.size())
            throw Exception ("you can't specify both a peaks file and orientations to be estimated at the same time");
        if (opt.size())
            ipeaks_data.reset (new Image::Buffer<value_type> (opt[0][0]));

        Image::check_dimensions (header, *ipeaks_data, 0, 3);
        npeaks = ipeaks_data->dim (3) / 3;
    }
    header.dim(3) = 3 * npeaks;
    Image::Buffer<value_type> peaks_data (argument[1], header);

    DataLoader loader (SH_data, mask_data.get());
    Processor processor (peaks_data, dirs, Math::SH::LforN (SH_data.dim (3)),
                         npeaks, true_peaks, threshold, ipeaks_data.get());

    Thread::run_queue (loader, Item(), Thread::multi (processor));
}
开发者ID:rodneyanderson,项目名称:mrtrix3,代码行数:62,代码来源:sh2peaks.cpp


示例19: check_and_update

void check_and_update (Image::Header& H, const conv_t conversion)
{

  const size_t lmax = Math::SH::LforN (H.dim(3));

  // Flag which volumes are m==0 and which are not
  const ssize_t N = H.dim(3);
  BitSet mzero_terms (N, false);
  for (size_t l = 2; l <= lmax; l += 2)
    mzero_terms[Math::SH::index (l, 0)] = true;

  // Open in read-write mode if there's a chance of modification
  typename Image::Buffer<value_type> buffer (H, (conversion != NONE));
  typename Image::Buffer<value_type>::voxel_type v (buffer);

  // Need to mask out voxels where the DC term is zero
  Image::Info info_mask (H);
  info_mask.set_ndim (3);
  info_mask.datatype() = DataType::Bit;
  Image::BufferScratch<bool> mask (info_mask);
  Image::BufferScratch<bool>::voxel_type v_mask (mask);
  size_t voxel_count = 0;
  {
    Image::LoopInOrder loop (v, "Masking image based on DC term...", 0, 3);
    for (loop.start (v, v_mask); loop.ok(); loop.next (v, v_mask)) {
      const value_type value = v.value();
      if (value && std::isfinite (value)) {
        v_mask.value() = true;
        ++voxel_count;
      } else {
        v_mask.value() = false;
      }
    }
  }

  // Get sums independently for each l
 
  // Each order has a different power, and a different number of m!=0 volumes.
  // Therefore, calculate the mean-square intensity for the m==0 and m!=0
  // volumes independently, and report ratio for each harmonic order
  Ptr<ProgressBar> progress;
  if (App::log_level > 0 && App::log_level < 2)
    progress = new ProgressBar ("Evaluating SH basis of image \"" + H.name() + "\"...", N-1);

  std::vector<float> ratios;

  for (size_t l = 2; l <= lmax; l += 2) {

    double mzero_sum = 0.0, mnonzero_sum = 0.0;
    Image::LoopInOrder loop (v, 0, 3);
    for (v[3] = ssize_t (Math::SH::NforL(l-2)); v[3] != ssize_t (Math::SH::NforL(l)); ++v[3]) {
      double sum = 0.0;
      for (loop.start (v, v_mask); loop.ok(); loop.next (v, v_mask)) {
        if (v_mask.value())
          sum += Math::pow2 (value_type(v.value()));
      }
      if (mzero_terms[v[3]]) {
        mzero_sum += sum;
        DEBUG ("Volume " + str(v[3]) + ", m==0, sum " + str(sum));
      } else {
        mnonzero_sum += sum;
        DEBUG ("Volume " + str(v[3]) + ", m!=0, sum " + str(sum));
      }
      if (progress)
      ++*progress;
    }

    const double mnonzero_MSoS = mnonzero_sum / (2.0 * l);
    const float power_ratio = mnonzero_MSoS/mzero_sum;
    ratios.push_back (power_ratio);

    INFO ("SH order " + str(l) + ", ratio of m!=0 to m==0 power: " + str(power_ratio) +
        ", m==0 power: " + str (mzero_sum));

  }

  if (progress)
    progress = NULL;

  // First is ratio to be used for SH basis decision, second is gradient of regression
  std::pair<float, float> regression = std::make_pair (0.0f, 0.0f);
  size_t l_for_decision;
  float power_ratio;

  // The gradient will change depending on the current basis, so the threshold needs to also
  // The gradient is as a function of l, not of even orders
  float grad_threshold = 0.02;

  switch (lmax) {

    // Lmax == 2: only one order to use
    case 2:
      power_ratio = ratios.front();
      l_for_decision = 2;
      break;

    // Lmax = 4: Use l=4 order to determine SH basis, can't check gradient since l=2 is untrustworthy
    case 4:
      power_ratio = ratios.back();
      l_for_decision = 4;
//.........这里部分代码省略.........
开发者ID:szho42,项目名称:mrtrix3,代码行数:101,代码来源:shbasis.cpp


示例20: run

void run () {

  Tractography::Properties properties;
  Tractography::Reader<float> file (argument[0], properties);

  const size_t num_tracks = properties["count"].empty() ? 0 : to<size_t> (properties["count"]);

  float step_size = 0.0;
  if (properties.find ("output_step_size") != properties.end())
    step_size = to<float> (properties["output_step_size"]);
  else
    step_size = to<float> (properties["step_size"]);

  std::vector<float> voxel_size;
  Options opt = get_options("vox");
  if (opt.size())
    voxel_size = opt[0][0];

  if (voxel_size.size() == 1)
    voxel_size.assign (3, voxel_size.front());
  else if (!voxel_size.empty() && voxel_size.size() != 3)
    throw Exception ("voxel size must either be a single isotropic value, or a list of 3 comma-separated voxel dimensions");

  if (!voxel_size.empty())
    INFO ("creating image with voxel dimensions [ " + str(voxel_size[0]) + " " + str(voxel_size[1]) + " " + str(voxel_size[2]) + " ]");

  Image::Header header;
  opt = get_options ("template");
  if (opt.size()) {
    Image::Header template_header (opt[0][0]);
    header = template_header;
    header.comments().clear();
    if (!voxel_size.empty())
      oversample_header (header, voxel_size);
  }
  else {
    if (voxel_size.empty())
      throw Exception ("please specify either a template image or the desired voxel size");
    generate_header (header, argument[0], voxel_size);
  }

  header.set_ndim (3);

  opt = get_options ("contrast");
  contrast_t contrast = opt.size() ? contrast_t(int(opt[0][0])) : TDI;

  opt = get_options ("stat_vox");
  vox_stat_t stat_vox = opt.size() ? vox_stat_t(int(opt[0][0])) : V_SUM;

  opt = get_options ("stat_tck");
  tck_stat_t stat_tck = opt.size() ? tck_stat_t(int(opt[0][0])) : T_MEAN;

  float gaussian_fwhm_tck = 0.0, gaussian_denominator_tck = 0.0;
  opt = get_options ("fwhm_tck");
  if (opt.size()) {
    if (stat_tck != GAUSSIAN) {
      INFO ("Overriding per-track statistic to Gaussian as a full-width half-maximum has been provided.");
      stat_tck = GAUSSIAN;
    }
    gaussian_fwhm_tck = opt[0][0];
    const float gaussian_theta_tck = gaussian_fwhm_tck / (2.0 * sqrt (2.0 * log (2.0)));
    gaussian_denominator_tck = 2.0 * gaussian_theta_tck * gaussian_theta_tck;
  } else if (stat_tck == GAUSSIAN) {
    throw Exception ("If using Gaussian per-streamline statistic, need to provide a full-width half-maximum for the Gaussian kernel using the -fwhm option");
  }

  opt = get_options ("colour");
  const bool colour = opt.size();

  opt = get_options ("map_zero");
  const bool map_zero = opt.size();

  if (colour) {
    header.set_ndim (4);
    header.dim(3) = 3;
    //header.set_description (3, "directionally-encoded colour");
    Image::Stride::set (header, Image::Stride::contiguous_along_axis (3, header));
  }

  // Deal with erroneous statistics & provide appropriate messages
  switch (contrast) {

    case TDI:
      if (stat_vox != V_SUM && stat_vox != V_MEAN) {
        INFO ("Cannot use voxel statistic other than 'sum' or 'mean' for TDI generation - ignoring");
        stat_vox = V_SUM;
      }
      if (stat_tck != T_MEAN)
        INFO ("Cannot use track statistic other than default for TDI generation - ignoring");
      stat_tck = T_MEAN;
      break;

    case PRECISE_TDI:
      if (stat_vox != V_SUM) {
        INFO ("Cannot use voxel statistic other than 'sum' for precise TDI generation - ignoring");
        stat_vox = V_SUM;
      }
      if (stat_tck != T_MEAN)
        INFO ("Cannot use track statistic other than default for precise TDI generation - ignoring");
      stat_tck = T_MEAN;
//.........这里部分代码省略.........
开发者ID:gkocevar,项目名称:mrtrix3,代码行数:101,代码来源:tckmap.cpp



注:本文中的image::Header类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ image::Image类代码示例发布时间:2022-05-31
下一篇:
C++ image::Box类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap