Example #1
0
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;

}
Example #2
0
void run () {

  Image::Header input_header (argument[0]);
  const size_t filter_index = argument[1];

  // Separate code path for FFT filter
  if (!filter_index) {

    // Gets preloaded by the FFT filter anyways, so just use a buffer
    // FIXME Had to use cdouble throughout; seems to fail at compile time even trying to
    //   convert between cfloat and cdouble...
    Image::Buffer<cdouble> input_data (input_header);
    Image::Buffer<cdouble>::voxel_type input_voxel (input_data);
    Image::Filter::FFT* filter = (dynamic_cast<Image::Filter::FFT*> (create_fft_filter (input_voxel)));

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

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

    if (get_options ("magnitude").size()) {

      Image::BufferScratch<cdouble> temp_data (header, "complex FFT result");
      Image::BufferScratch<cdouble>::voxel_type temp_voxel (temp_data);
      (*filter) (input_voxel, temp_voxel);

      header.datatype() = DataType::Float32;
      Image::Buffer<float> output_data (argument[2], header);
      Image::Buffer<float>::voxel_type output_voxel (output_data);

      Image::LoopInOrder loop (output_voxel);
      for (loop.start (temp_voxel, output_voxel); loop.ok(); loop.next (temp_voxel, output_voxel))
        output_voxel.value() = std::abs (cdouble(temp_voxel.value()));

    } else {

      Image::Buffer<cdouble> output_data (argument[2], header);
      Image::Buffer<cdouble>::voxel_type output_voxel (output_data);
      (*filter) (input_voxel, output_voxel);

    }

    delete filter;
    return;

  }

  Image::BufferPreload<float> input_data (input_header);
  Image::BufferPreload<float>::voxel_type input_voxel (input_data);

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

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

  Image::Buffer<float> output_data (argument[2], header);
  Image::Buffer<float>::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: assert (0); break;
    case 1: (*dynamic_cast<Image::Filter::Gradient*> (filter)) (input_voxel, output_voxel); break;
    case 2: (*dynamic_cast<Image::Filter::Median*>   (filter)) (input_voxel, output_voxel); break;
    case 3: (*dynamic_cast<Image::Filter::Smooth*>   (filter)) (input_voxel, output_voxel); break;
  }

  delete filter;

}