Linking events in skimage.viewer

Nadav Horesh nadavh.horesh at gmail.com
Mon Dec 23 09:10:59 EST 2013


Tony,
I found the .connect_event method of the ImageViewer class just before
I got the reply from you, and it roughly works. I say roughly because
in the application there are some sliders that I added (not a part of
the built-in plugins), and what I see that I see an image update only
after I touch the sliders. In the linetool, however, the response is
immediate.

Code snippet:

class Cimage:
.
.
.
    def create_window(self):
        self.view = viewer.ImageViewer(self.rgb_image)

        plugin = OverlayPlugin(image_filter=self.image_update)
        plugin += Slider('gamma', 1.0, 3.0, value=self.gamma,
orientation='vertical')
        plugin += Slider('mat mix', 0.0, 1.0, value=0.0,
update_on='move', orientation='vertical')
        plugin += Slider('wb mix', 0.0, 1.0, value=0.0,
update_on='move', orientation='horizontal')

        self.view += plugin
        self.view.connect_event('key_press_event', self.key_press)
        self.view.setWindowTitle(self.recname)
        self.view.show()
.
.
.
in the key_press method execution chain I have
self.view.image = new_image

so the image is updated, but it does not trigger a display update.



Steve,
Here is your code after some typos correction:

#! /usr/bin/python

from __future__ import print_function

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
import matplotlib.pyplot as plt
from skimage import data


class MyCanvas(FigureCanvasQTAgg):

    def mousePressEvent(self, event):
        #pass
        print('press')
        self.image = self.image[::-1]

def main():
    image = data.camera()
    f, ax = plt.subplots()
    f.canvas = MyCanvas(f)
    ax.imshow(image, interpolation='nearest')
    h, w = image.shape
    plt.show()


if __name__ == '__main__':
    main()

Running it I see that the method mousePressEvent is not being called

 I'll be happy to know if there is something to follow and build an
application based on the viewer module.

Thank you both very much

Nadav


2013/12/23 Steven Silvester <steven.silvester at gmail.com>:
> Nadav,
>
> The canvas itself is a matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.
> If you wanted, you could subclass that class and provide your own
> mousePressEvent and friends. Something like:
>
> from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
> import matplotlib.pyplot as plt
> from skimage import data
>
>
> class MyCanvas(FigureCanvasQtAgg):
>
>     def mousePressEvent(self, event):
>         pass
>
> def main():
>     image = data.camera()
>     f, ax = plt.subplots()
>     f.canvas = MyCanvas()
>     ax.imshow(image, interpolation='nearest')
>     h, w = image.shape
>     plt.show()
>
> On Wednesday, December 18, 2013 2:13:02 AM UTC-6, Nadav Horesh wrote:
>>
>> I
>> I started to build an interactive image exploration utility based on
>> matplotlib.  Recently, following a link on this list, I encountered
>> skimage.viewer, and found that the plugins architecture matches my needs.
>> I could not find how to link keyboard and mouse events (and maybe buttons)
>> to plugins. Any suggestions?
>>
>> I am using version 0.93 on linux (I can install the pre 0.10, if needed)
>>
>>  Thanks,
>>
>>     Nadav
>
> --
> You received this message because you are subscribed to the Google Groups
> "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scikit-image+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



More information about the scikit-image mailing list