Example #1
0
void run ()
{

  Header H_in = Header::open (argument[0]);
  Sparse::Image<FixelMetric> fixel (H_in);

  const size_t lmax = 8;
  const size_t N = Math::SH::NforL (lmax);
  Math::SH::aPSF<default_type> aPSF (lmax);

  Header H_out (H_in);
  H_out.datatype() = DataType::Float32;
  H_out.datatype().set_byte_order_native();
  const size_t sh_dim = H_in.ndim();
  H_out.ndim() = H_in.ndim() + 1;
  H_out.size (sh_dim) = N;

  auto sh = Image<float>::create (argument[1], H_out);
  std::vector<default_type> values;
  Eigen::Matrix<default_type, Eigen::Dynamic, 1> apsf_values;

  for (auto l1 = Loop("converting sparse fixel data to SH image", fixel) (fixel, sh); l1; ++l1) {
    values.assign (N, 0.0);
    for (size_t index = 0; index != fixel.value().size(); ++index) {
      apsf_values = aPSF (apsf_values, fixel.value()[index].dir);
      const default_type scale_factor = fixel.value()[index].value;
      for (size_t i = 0; i != N; ++i)
        values[i] += apsf_values[i] * scale_factor;
    }
    for (auto l2 = Loop(sh_dim) (sh); l2; ++l2)
      sh.value() = values[sh.index(sh_dim)];
  }

}
Example #2
0
void run ()
{
  Header H_in = Header::open (argument[0]);
  Sparse::Image<FixelMetric> in (H_in);

  const int op = argument[1];

  Header H_out (H_in);
  H_out.datatype() = DataType::Float32;
  H_out.datatype().set_byte_order_native();
  H_out.keyval().erase (Sparse::name_key);
  H_out.keyval().erase (Sparse::size_key);
  if (op == 10) { // count
    H_out.datatype() = DataType::UInt8;
  } else if (op == 13 || op == 14) { // dec
    H_out.set_ndim (4);
    H_out.size (3) = 3;
  } else if (op == 15 || op == 16 || op == 17) { // split_*
    H_out.set_ndim (4);
    uint32_t max_count = 0;
    for (auto l = Loop ("determining largest fixel count", in) (in); l; ++l)
      max_count = std::max (max_count, in.value().size());
    if (max_count == 0)
      throw Exception ("fixel image is empty");
    // 3 volumes per fixel if performing split_dir
    H_out.size(3) = (op == 17) ? (3 * max_count) : max_count;
  }

  auto out = Image<float>::create (argument[2], H_out);

  auto opt = get_options ("weighted");
  const bool weighted = opt.size();

  auto loop = ThreadedLoop ("converting sparse fixel data to scalar image", in);

  switch (op) {
    case 0:  loop.run (Mean       (weighted), in, out); break;
    case 1:  loop.run (Sum        (weighted), in, out); break;
    case 2:  loop.run (Product    (weighted), in, out); break;
    case 3:  loop.run (RMS        (weighted), in, out); break;
    case 4:  loop.run (Var        (weighted), in, out); break;
    case 5:  loop.run (Std        (weighted), in, out); break;
    case 6:  loop.run (Min        (weighted), in, out); break;
    case 7:  loop.run (Max        (weighted), in, out); break;
    case 8:  loop.run (AbsMax     (weighted), in, out); break;
    case 9:  loop.run (MagMax     (weighted), in, out); break;
    case 10: loop.run (Count      (weighted), in, out); break;
    case 11: loop.run (Complexity (weighted), in, out); break;
    case 12: loop.run (SF         (weighted), in, out); break;
    case 13: loop.run (DEC_unit   (weighted), in, out); break;
    case 14: loop.run (DEC_scaled (weighted), in, out); break;
    case 15: loop.run (SplitSize  (weighted), in, out); break;
    case 16: loop.run (SplitValue (weighted), in, out); break;
    case 17: loop.run (SplitDir   (weighted), in, out); break;
  }

}
Example #3
0
void run ()
{
  auto header = Header::open (argument[0]);
  Sparse::Image<FixelMetric> input (argument[0]);

  Sparse::Image<FixelMetric> output (argument[1], header);

  for (auto i = Loop ("computing log", input) (input, output); i; ++i) {
    output.value().set_size (input.value().size());
    for (size_t fixel = 0; fixel != input.value().size(); ++fixel) {
      output.value()[fixel] = input.value()[fixel];
      output.value()[fixel].value = std::log (input.value()[fixel].value);
    }
  }
}