Qt-MPL viewer #229

merged 62 commits into from Aug 24, 2012


None yet

2 participants

tonysyu commented Jul 20, 2012

Alternate implementation of image viewer using Matplotlib to draw the image canvas and Qt for drawing widgets. This viewer is an alternative to the pure Matplotlib version in PR #165. Explicitly using Qt overcomes many of the deficiencies of using Matplotlib widgets and allows full control of menus and toolbars.

This viewer has 3 main parts:

  • An ImageViewer class that shows images.
  • A Plugin class (and subclasses) to manipulate or measure images.
  • Widgets for interacting with manipulation and measurement functions.
tonysyu added some commits Jul 20, 2012
@tonysyu tonysyu ENH: Add orientation kwarg to IntelligentSlider 81764f6
@tonysyu tonysyu ENH: Add image viewer based on Qt and Matplotlib c27119b
@tonysyu tonysyu API change: switch order of image viewer and callback arguments. 1903ed8
@tonysyu tonysyu Add PlotPlugin and cleanup code. 6b591e2
@tonysyu tonysyu Add LineProfile plugin. afd33af
@tonysyu tonysyu Fix: Move on_draw method to base Plugin 47d5f02
@tonysyu tonysyu Clean up old code and add docstrings. fb3f201
@tonysyu tonysyu Delete overlay when deleting plugin. bd3ee78
@tonysyu tonysyu Add docstring for `overlay` and reorder methods. 9f0449e
@tonysyu tonysyu Show coordinate and intensity info in status bar. c21fe1c
@tonysyu tonysyu Add plugin names 221cf73
@tonysyu tonysyu Add `update_on` parameter to slider and allow update on release. 4739165
@tonysyu tonysyu Refactor image overlays to special plugin base class. 48ac757
@tonysyu tonysyu Move OverlayPlugin and PlotPlugin to their own modules. 5171121
@tonysyu tonysyu Change ImageViewer to automatically call plugins. 4d74772
@tonysyu tonysyu ENH: Align image and plugin windows 31c2810
@tonysyu tonysyu Fix `add_argument`.
`arguments` is a list, but I was treating it like a dict.
@tonysyu tonysyu ENH: Simplify creation of Slider widget. 887a911
@tonysyu tonysyu ENH: Rename callback functions for clarity. 9b4c622
@tonysyu tonysyu ENH: Simplify widget addition. 385382f
@tonysyu tonysyu ENH: Move closeEvent definition to base class. 3271e21
@tonysyu tonysyu ENH: Generalize add_widget function. 0644958
@tonysyu tonysyu ENH: Allow `Plugin.add_widget` to hook into Plugin attributes.
The `ptype` parameter of widget can now be set to 'plugin'. When this is the case, the plugin will set a plugin attribute whenever the widget is updated.

As an example, this commit adds a ComboBox widget which is hooked into the overlay color of the OverlayPlugin.
@tonysyu tonysyu Make alpha value to ClearColormap adjustable. 9d1df0c
@tonysyu tonysyu API Change: Attach ImageViewer to Plugin after init.
Plugin is now added to the viewer using an inplace add on the viewer instead of on initialization of the plugin. This change means that operations requiring the viewer must be delayed until attach operation.
@tonysyu tonysyu Minor cleanup. df18d40
@tonysyu tonysyu Change image_viewer to Plugin property.
Raise an error when using Plugin.image_viewer before it is set. This error prevents other, more obscure, errors from getting raised.
@tonysyu tonysyu ENH: Let Qt handle most of the window sizing. 92ca837
@tonysyu tonysyu Rename (dis)connect_event to (dis)connect_image_events.
This clarifies action since these events are on the image viewer, not the plugin.
@tonysyu tonysyu DOC: Add todo note daae405
@tonysyu tonysyu ENH: Display overlay by default 0e8f444
@tonysyu tonysyu ENH: filter image when Plugin is attached to ImageViewer 1ae662f
@tonysyu tonysyu BUG: in-place add should return object
Actually, I didn't mean to add `__iadd__` a couple of commits ago, so this was supposed to be an enhancement that allows you to access `add_widget` using in place adding.
@tonysyu tonysyu ENH: Add example of adding widgets to plugin 6182cc9
@tonysyu tonysyu ENH: Change inplace-add to normal add to support alternate syntax
Widgets can be added to Plugins inline, and Plugins can be added inline to Viewers.
@tonysyu tonysyu BUG: Don't override `image_filter` method if defined by subclass c2d2919
@tonysyu tonysyu STY: Remove unused `add_artist` method. ff98b05
@tonysyu tonysyu DOC: Improve docstrings for ImageViewer.
Oops: also changed added leading underscore to `update_status_bar`.
@tonysyu tonysyu DOC: Improve docstrings for Plugin class. 51e61b3
@tonysyu tonysyu ENH: allow color to be set by name 260a336
@tonysyu tonysyu STY: reorder methods for clarity. d72baa4
@tonysyu tonysyu DOC: clean up docstring for PlotPlugin 49bdc3a
@tonysyu tonysyu DOC: cleanup docstring and reuse parameter defined by parent class f261e76
@tonysyu tonysyu DOC: Add class docstring 9285898
@tonysyu tonysyu STY: Refactor MatplotlibCanvas from ImageCanvas and PlotCanvas. 539b12d
@tonysyu tonysyu ENH: Create new Slider with editbox.
Also, make the behavior more consistent between updating plugin and widget parameters.
@tonysyu tonysyu Revert modifications of IntelligentSlider.
Slider added in last commit removes the need for these modifications.
@tonysyu tonysyu Remove lineprofile temporarily (saved in a branch) 7615a85
@tonysyu tonysyu Remove unused import 1290705
@tonysyu tonysyu STY: Refactor BaseWidget from Slider and ComboBox 449f3e4
@tonysyu tonysyu BUG: Fix behavior when initial overlay limits are bad.
Intensity limits are calculated by the initial input image. If this image has, for example, all black pixels, then subsequent overlays will remain all black because of the initialized limits. Set limits based on data type to fix this issue.
@tonysyu tonysyu DOC: Explain use of callback parameter. 1000c73
@tonysyu tonysyu DOC: Add explanation of add operator. 7d533e1
@tonysyu tonysyu BUG: Fix scaling when setting default slider value. 3340d06
@tonysyu tonysyu ENH: Add Slider `value_type` to allow int values. ce017cc
@tonysyu tonysyu ENH: Add RequiredAttr to raise warnings when attr not set. 54af417
@tonysyu tonysyu DOC: Clean up docstring for Slider 9ac4272
@tonysyu tonysyu ENH: Add SaveButtons widget. 4ab583b
@tonysyu tonysyu BUG: reset image when plugin is closed. 398b320
@tonysyu tonysyu ENH: Add OK/Cancel buttons e96aca5
@tonysyu tonysyu STY: Tweak button sizes. cfd0b84
@tonysyu tonysyu BUG: Update filter when edit-box is changed. ffe2eba
@stefanv stefanv commented on the diff Aug 24, 2012
+ Also note that `attach` automatically calls the filter function so that
+ the image matches the filtered value specified by attached widgets.
+ """
+ self.setParent(image_viewer)
+ self.setWindowFlags(Qt.Dialog)
+ self.image_viewer = image_viewer
+ self.image_viewer.plugins.append(self)
+ #TODO: Always passing image as first argument may be bad assumption.
+ self.arguments.append(self.image_viewer.original_image)
+ if self.draws_on_image:
+ self.connect_image_event('draw_event', self.on_draw)
+ # Call filter so that filtered image matches widget values
+ self.filter_image()
stefanv Aug 24, 2012 Member

Adding 3 widgets then runs the filter 3 times?

tonysyu Aug 25, 2012 Member

I think the filtering should only occur once. attach is called when the plugin is attached to the viewer. In contrast, add_widget is called each time a widget is added to a plugin.

@stefanv stefanv commented on the diff Aug 24, 2012
@@ -0,0 +1,91 @@
+import numpy as np
+from skimage.util import dtype
+from .base import Plugin
+from ..utils import ClearColormap
+#TODO: Maybe this bool definition should be moved to skimage.util.dtype.
stefanv Aug 24, 2012 Member

Let's do that.

tonysyu Aug 25, 2012 Member

Actually, there's no need since PR#260 adds bool support. I did, however, remove the dtype_range hack and, instead, use the new bool support. I pushed directly to master because it seemed minor. Let me know if I shouldn't have done so.

@stefanv stefanv merged commit 7490322 into scikit-image:master Aug 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment