Class: FSL::BET

Inherits:
Object
  • Object
show all
Defined in:
lib/fsl-ruby/bet.rb

Overview

bet <input> <output> [options]

Constant Summary collapse

@@command_path =

-o generate brain surface outline overlaid onto original image -m generate binary brain mask -s generate rough skull image (not as clean as what betsurf generates) -n don’t generate the default brain image output -f <f> fractional intensity threshold (0->1); default=0.5; smaller values give larger brain outline estimates -g <g> vertical gradient in fractional intensity threshold (-1->1); default=0; positive values give larger brain outline at bottom, smaller at top -r <r> head radius (mm not voxels); initial surface sphere is set to half of this -c < x y z> centre-of-gravity (voxels not mm) of initial mesh surface. -t apply thresholding to segmented brain image and mask -e generates brain surface as mesh in .vtk format.

'/usr/local/fsl/bin/bet'
@@options_map =
{ outline: '-o',
  mask: '-m',
  skull: '-s',
  no_output: '-n',
  fi_threshold: '-f',
  v_gradient: '-g',
  radius: '-r',
  centre: '-c',
  thresholding: '-t',
  mesh: '-e'
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_file, output_dir, opt = {}) ⇒ BET

Returns a new instance of BET.



38
39
40
41
42
43
# File 'lib/fsl-ruby/bet.rb', line 38

def initialize(input_file, output_dir, opt = {})
  @input_file = input_file
  @basename = File.basename(input_file, '.nii.gz')
  @output_dir = output_dir
  @opt = opt
end

Class Method Details

.command_pathObject



21
22
23
# File 'lib/fsl-ruby/bet.rb', line 21

def self.command_path
  @@command_path
end

.command_path=(path) ⇒ Object



17
18
19
# File 'lib/fsl-ruby/bet.rb', line 17

def self.command_path=(path)
  @@command_path = path
end

.options_mapObject



45
46
47
# File 'lib/fsl-ruby/bet.rb', line 45

def self.options_map
  @@options_map
end

Instance Method Details

#argument_listObject



61
62
63
# File 'lib/fsl-ruby/bet.rb', line 61

def argument_list
  map_options(@opt).collect {|k,v| v}.join(' ')
end

#commandObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fsl-ruby/bet.rb', line 65

def command
  command_str = "#{self.class.command_path} #{@input_file} #{@output_dir}/#{@basename}_brain #{argument_list}"
  puts "Running BET with command: #{command_str}..."
  result = `#{command_str}`
  exit_code = $?
  case exit_code
    when 0
      puts "Done running BET."
      return result
    else
      puts "An error ocurred while running BET"
          #   exit_error = Dcm2nii::Runner::UnexpectedExitError.new
          #   exit_error.exit_code = exit_code
          #   raise exit_error
          # end
  end
end

#get_resultObject



83
84
85
# File 'lib/fsl-ruby/bet.rb', line 83

def get_result
      return `find #{@output_dir} -name *_brain.nii*`.chomp
end

#map_options(opt = {}) ⇒ Object



57
58
59
# File 'lib/fsl-ruby/bet.rb', line 57

def map_options(opt ={})
  opt.inject({}) { |h, (k, v)| h[k] = (self.class.options_map[k] + ' ' + map_vals(v)); h }
end

#map_vals(val) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/fsl-ruby/bet.rb', line 49

def map_vals(val)
  if val == true || val == false
    ''
  else
    val.to_s
  end
end