New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced widgets #452

merged 103 commits into from Oct 19, 2014


None yet
3 participants

nontas commented Oct 1, 2014

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:

from IPython.display import display

# get the widget
low_level_widget = low_level_options(arguments)

# visualize it

# Format it. THis can only be done after the actual display!

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


  • 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?
  • Add a markeredgewidth field in plot_options().

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!

@jabooth jabooth added the in progress label Oct 1, 2014

@jabooth jabooth added the enhancement label Oct 2, 2014

@jabooth jabooth added this to the 0.4.0 milestone Oct 2, 2014


This comment has been minimized.


nontas commented Oct 2, 2014

The last commits add a view_widget() method to the AAM, CLM, Image and FittingResult classes and their subclasses.

@jabooth jabooth referenced this pull request Oct 3, 2014


additional widgets #456


This comment has been minimized.


patricksnape commented Oct 18, 2014

I have a couple of updates to this. So keep this on hold for now.

patricksnape added some commits Oct 18, 2014

Refactor the widget strings so they are cleaner
Just create a couple of simple functions that take raw strings
and spit out the latex code for the widgets. Looks a bit cleaner
in code and should make it easier to make more widgets.

This comment has been minimized.


patricksnape commented Oct 18, 2014

Made a few fixes. Looks good to me. There's a few True, False settings that are probably redundant (in general if BOOLEAN: a = True else: b = False can be reduced to a = BOOLEAN). But I'm not sure how to test the values properly because I tried printing the values and can't find where some of the functions get fired. But it isn't a big deal to be honest.

Outside of that, I am +1 this pull for the release 😄


This comment has been minimized.


jabooth commented Oct 19, 2014

Great that this is ready to come in, but we have a merge conflict against master which I'm not sure how to resolve. Seems some changes to visualize/widgets/ went in on a separate branch that were never incorporated. My gut feeling is that we basically ignore them since this file has essentially been re-written in this PR but can someone check? Soon as that's resolved we can bring it in.

Nontas Antonakos and others added some commits Oct 19, 2014

Nontas Antonakos
Merge remote-tracking branch 'upstream/master' into advanced_widgets
Nontas Antonakos
Fix background error for images
Change from 1 to a percentage of the max

jabooth added a commit that referenced this pull request Oct 19, 2014

@jabooth jabooth merged commit 9d8b095 into menpo:master Oct 19, 2014

1 of 2 checks passed

continuous-integration/appveyor Waiting for AppVeyor build to complete
continuous-integration/travis-ci The Travis CI build passed

@jabooth jabooth deleted the nontas:advanced_widgets branch Oct 19, 2014

@jabooth jabooth removed the in progress label Oct 19, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment