Package topo :: Package patterns :: Module image :: Class GenericImage
[hide private]
[frames] | no frames]

Class GenericImage

source code

                                  object --+        
                                           |        
base.parameterizedobject.ParameterizedObject --+    
                                               |    
          base.patterngenerator.PatternGenerator --+
                                                   |
                                                  GenericImage
Known Subclasses:
misc.robotics.CameraImage, FileImage

Generic 2D image generator.

Generates a pattern from a Python Imaging Library image object. Subclasses should override the _get_image method to produce the image object.

The background value is calculated as an edge average: see edge_average(). Black-bordered images therefore have a black background, and white-bordered images have a white background. Images with no border have a background that is less of a contrast than a white or black one.

At present, rotation, scaling, etc. just resample; it would be nice to support some interpolation options as well.



Nested Classes [hide private]

Inherited from base.parameterizedobject.ParameterizedObject: __metaclass__

Instance Methods [hide private]
 
__setup_pattern_sampler(self)
If a new filename or whole_image_output_fn is supplied, create a PatternSampler based on the image found at filename.
source code
 
function(self, params)
Function to draw a pattern that will then be scaled and rotated.
source code
 
_get_image(self, params)
Get a new image, if necessary.
source code
 
__getstate__(self)
Return the object's state (as in the superclass), but replace the '_image' attribute's Image with a string representation.
source code
 
__setstate__(self, state)
Load the object's state (as in the superclass), but replace the '_image' string with an actual Image object.
source code

Inherited from base.patterngenerator.PatternGenerator: __call__

Inherited from base.parameterizedobject.ParameterizedObject: __init__, __repr__, __str__, as_uninitialized, debug, defaults, force_new_dynamic_value, get_param_values, get_value_generator, inspect_value, message, print_param_values, script_repr, verbose, warning

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Methods [hide private]

Inherited from base.parameterizedobject.ParameterizedObject: params, print_param_defaults

Class Variables [hide private]
  __abstract = True
bool(x) -> bool
  output_fn = <topo.base.parameterclasses.ClassSelectorParameter...
Optional function to apply to the pattern array after it has been created.
  aspect_ratio = <topo.base.parameterclasses.Number object at 0x...
Ratio of width to height; size*aspect_ratio gives the width.
  size = Number(default= 1.0, bounds= (0.0, None), softbounds= (...
Height of the image.
  size_normalization = <topo.base.parameterclasses.Enumeration o...
How to scale the initial image size relative to the default area of 1.0.
  whole_image_output_fn = <topo.base.parameterclasses.ClassSelec...
Function applied to the whole, original image array (before any cropping).
  pattern_sampler_type = <topo.base.parameterizedobject.Paramete...
The type of PatternSampler to use to resample/resize the image.

Inherited from base.patterngenerator.PatternGenerator: bounds, mask, offset, orientation, position, scale, x, xdensity, y, ydensity

Inherited from base.parameterizedobject.ParameterizedObject: name, print_level

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__setup_pattern_sampler(self)

source code 

If a new filename or whole_image_output_fn is supplied, create a PatternSampler based on the image found at filename.

The PatternSampler is given the whole image array after it has been converted to grayscale.

function(self, params)

source code 

Function to draw a pattern that will then be scaled and rotated.

Instead of implementing __call__ directly, PatternGenerator subclasses will typically implement this helper function used by __call__, because that way they can let __call__ handle the scaling and rotation for them. Alternatively, __call__ itself can be reimplemented entirely by a subclass (e.g. if it does not need to do any scaling or rotation), in which case this function will be ignored.

Overrides: base.patterngenerator.PatternGenerator.function
(inherited documentation)

_get_image(self, params)

source code 

Get a new image, if necessary.

If necessary as indicated by the parameters, get a new image, assign it to self._image and return True. If no new image is needed, return False.

__getstate__(self)

source code 
Return the object's state (as in the superclass), but replace the '_image' attribute's Image with a string representation.
Overrides: base.parameterizedobject.ParameterizedObject.__getstate__

__setstate__(self, state)

source code 
Load the object's state (as in the superclass), but replace the '_image' string with an actual Image object.
Overrides: base.parameterizedobject.ParameterizedObject.__setstate__

Class Variable Details [hide private]

__abstract

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

Value:
True

output_fn

Optional function to apply to the pattern array after it has been created. This function can be used for normalization, thresholding, etc.
Value:
ClassSelectorParameter(OutputFn, default= IdentityOF())

aspect_ratio

Ratio of width to height; size*aspect_ratio gives the width.
Value:
Number(default= 1.0, bounds= (0.0, None), softbounds= (0.0, 2.0), precedence= 0.31\
, doc= """
        Ratio of width to height; size*aspect_ratio gives the width.""")

size

Height of the image.
Value:
Number(default= 1.0, bounds= (0.0, None), softbounds= (0.0, 2.0), precedence= 0.30\
, doc= "Height of the image.")

size_normalization

How to scale the initial image size relative to the default area of 1.0.
Value:
Enumeration(default= 'fit_shortest', available= ['fit_shortest', 'fit_longest', 's\
tretch_to_fit', 'original'], precedence= 0.95, doc= """
        How to scale the initial image size relative to the default area of 1.0.""\
")

whole_image_output_fn

Function applied to the whole, original image array (before any cropping).
Value:
ClassSelectorParameter(OutputFn, default= DivisiveNormalizeLinf(), precedence= 0.9\
6, doc= """
        Function applied to the whole, original image array (before any cropping).\
""")

pattern_sampler_type

The type of PatternSampler to use to resample/resize the image.
Value:
Parameter(default= PatternSampler, doc= """
        The type of PatternSampler to use to resample/resize the image.""")