Class: SciYAG::Backends::SmoothFilter

Inherits:
Filter
  • Object
show all
Includes:
Dobjects
Defined in:
lib/SciYAG/Backends/filters/smooth.rb

Overview

A simple gaussian filter. You’d better give it an odd number.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Filter

describe

Methods included from Descriptions::DescriptionExtend

#base_ancestor?, #description, #description_hash, #description_hash_base, #description_list, #description_list_base, extend_object, #inherit, #init_param, #init_params, #lookup_description_extend_ancestor, #param, #param_noaccess, #register_description, #set_description, #set_description_hash_base, #set_description_list_base

Methods included from Descriptions::DescriptionInclude

#description, #fill_parser, #long_name, #parser_banner, #parser_options

Constructor Details

#initialize(nb) ⇒ SmoothFilter

Returns a new instance of SmoothFilter.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/SciYAG/Backends/filters/smooth.rb', line 31

def initialize(nb) 
  nb = nb.to_i
  if nb < 2
    warn "Invalid parameter nb #{nb}, using 5"
    nb = 5
  end
  # initializes to binomial coefficients
  @kernel = Dvector.new(nb) { |i|
    SmoothFilter.cnk(nb,i)
  }
  @mid = nb - nb/2 - 1
end

Class Method Details

.cnk(n, k) ⇒ Object

Binomial coefficients.



46
47
48
49
50
51
# File 'lib/SciYAG/Backends/filters/smooth.rb', line 46

def SmoothFilter.cnk(n,k)
  res = 1.0
  n.downto(n - k) { |i| res *= i}
  k.downto(1) {|i| res = res/i }
  return res
end

Instance Method Details

#apply(f) ⇒ Object

There you go: a simple averageing filter.



54
55
56
# File 'lib/SciYAG/Backends/filters/smooth.rb', line 54

def apply(f)
  return Function.new(f.x, f.y.convolve(@kernel, @mid))
end

#apply!(f) ⇒ Object



58
59
60
# File 'lib/SciYAG/Backends/filters/smooth.rb', line 58

def apply!(f)
  f.y.replace(f.y.convolve(@kernel, @mid))
end