menpo/menpo — pull request #452 by nontas (2014-10-01 22:10:25+00:00)
Title: Advanced widgets

This PR updates the widgets introduced by #412 . The basic idea is that the widgets are no longer based on the `interact()` method. Instead we design our own widgets by creating low level ones that can by combined to design higher level ones.

#### Basic widgets
The basic widgets this PR provides are:
* `visualize_images()`
* `visualize_shape_model()`
* `visualize_appearance_model()`
* `visualize_aam()`
* `visualize_fitting_results()`
* `plot_ced()`

They all share the following characteristics:
* They all support to get as input a `list` of objects which can have different properties between them, e.g. images with different channels, aam with different feature per level, models with different number of components, fitting results with different number of iterations.
* Apart from their widget-specific arguments, they all have two common arguments:
1. `figure_size`: the initial size of the figure in inches.
2. `popup`: If `True`, then the widget appears in a separate pop-up window (only the widget options, not the actual figure).
* They all have a _"Save figure"_ tab, which allows to export the plotted figure as an image of any format (e.g. png, jpg, pdf, eps, ps) with customizable options such as paper size, dpi etc.
* The PR introduces inline animations. They are used in the `visualize_images()` widget as well as the `visualize_fitting_results()` for animating either through the actual images or the fitting iterations.

Some widget-specific characteristics:
* For `visualize_shape_model()`, `visualize_appearance_model()` and `visualize_aam()` the user can ask for different number of sliders per level.
* The `visualize_aam()` is now called from the `view()` method of the `AAM` (and the `PatchBasedAAM`) class.
* The `visualize_shape_model()` is now called from the `view()` method of the `CLM` class.

#### Low level (helper) widgets
All the above widgets are a mixture of some lower level ones. These are:
* `animation_options()`
* `channel_options()`
* `landmark_options()`
* `model_parameters()`
* `plot_options()`
* `figure_options()` and `figure_options_two_scales()`
* `save_figure_options()`
* `final_result_options()`
* `iterations_result_options()`
* `index_selection_buttons()`
* `index_selection_slider()`
All the lower-level widgets have also an `update_*()` method that updates the state/attributes of their parts and a `format_*()` method that controls their structure (alignment, appearance etc.).

Note that these methods do not actually display the widget; they just return it. So a typical call of such a widget looks like:
```Python
from IPython.display import display

# get the widget
low_level_widget = low_level_options(arguments)

# visualize it
display(low_level_widget)

# Format it. THis can only be done after the actual display!
format_low_level_options(low_level_widget)

# if the arguments changed then the widget can be updated as:
update_low_level_options(low_level_widget, arguments)
```

#### To-do
- [ ] Correct the _"Plot displacements"_ method in `visualize_fitting_results()` after #447 gets merged.
- [ ] The `visualize_fitting_results()` needs to be called by the `view()` method of the `FittingResult` (and the `MultilevelFittingResult`) class.
- [ ] Should the `visualize_images()` be called from the `view()` method of an `Image` instance? Or maybe add a `kwarg` for such a thing?

#### Future work
Some ideas for future work/improvements are:
1. Create a `visualize_aam_fitting_results()` widget that takes advantage of the `aam_reconstructions`, `warped_images`, `appearance_reconstructions`, `costs` and `error_images` properties of the `AAMMultilevelFittingResult` class.
2. Create widgets for the `AAMBuilder`, `CLMBuilder` and `SDFitter` classes.
3. Create widget for interactive trimming of the components of a `PCAModel` instance.
4. Create Youtube videos of the widgets and `menpo` in general.

I'm sure that the code is not at its best shape. If you look at it you will certainly find corrections/improvements which we can discuss. Guys please do try the 6 basic widgets. Try to press all the buttons they have in order to give me feedback about any bugs!

Finally, please do propose me any stylistic changes you think are required.and ask for any new widget you wish!