question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Applying successives filters / function on the same layer

See original GitHub issue

❓ Questions and Help

First of all, thank you for magicgui, just started playing with it and it’s pretty awesome. I have a pretty simple question:

If I take the example from the documentation:

@magicgui(
        auto_call=True,
        sigma={"widget_type": QDoubleSlider, "maximum": 6, "fixedWidth": 400},
        mode={"choices": ["reflect", "constant", "nearest", "mirror", "wrap"]},
    )
    def gaussian_blur(layer: Image, sigma: float = 1.0, mode="nearest") -> Image:
        """Apply a gaussian blur to ``layer``."""
        if layer:
            return skimage.filters.gaussian(layer.data, sigma=sigma, mode=mode)

But let say I wanted to apply skimage.filters.median as well to the same layer image while being able to adjust the selem size, what would be the best and cleanest way to go about it? I try few things but ended work on 2 separates layers.

[ ] I have searched the documentation

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tlambert03commented, May 23, 2020

The core idea here is that magicgui basically just brokers mappings between types and widgets (in the function signature), or return annotations and callbacks. magicgui doesn’t know anything about napari, (it doesn’t import napari or depend on napari in any way), but it does allow third party packages to “register” their own custom classes with magicgui so as to provide “sane defaults”: for instance, when you annotate a function parameter as a napari Layer def function(image1: napari.layers.Image):, then magic gui will render that as a dropdown box with all of the current viewer image layers because napari has told it to do so. Had napari not done that, then magicgui would have no idea what to do with a parameter of type napari.layers.Image (unless the user instructed it manually).

If at any point you want to “opt-out” of the behavior that a third party package like napari has registered, then you either can not annotate your parameter or return type as that third party class … in which case you’ll need to tell magicgui what to do with that type, by either directly specifying the widget_type argument (manually passing a QtWidget for magicgui to use), or you can override the third party behavior by registering your own widget for the corresponding type:

from magicgui import register_type

register_type(napari.layers.Layer, widget_type=MyCustomQtWidget)
1reaction
tlambert03commented, May 21, 2020

That’s definitely a use case I’d like to support here! Ultimately, I’d like these widgets to be composable, and nestable (e.g. using a function as a parameter makes a nested widget).

For what it’s worth, I had a project that I was working on for a while that attempts to build that sort of “autogui” from an arbitrary sequence of python functions: mosaicpy, (see the “basic idea” in the readme there). I think it would be possible here to do something similar: make a “list item widget” where the items in the list are (sortable) functions, each of which is rendered as a magicgui, and outputs are chained together…

Thanks for your note! I’ll definitely keep this use case in mind and try to work on something soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apply Smart Filters in Photoshop - Adobe Support
To apply a Smart Filter to a regular layer, select the layer, and choose Filter > Convert For Smart Filters, and click OK....
Read more >
How to Visualize Filters and Feature Maps in Convolutional ...
The feature maps that result from applying filters to input images and to feature maps output by prior layers could provide insight into...
Read more >
Apply filters (Map Viewer Classic) - ArcGIS Online
Work with existing filters · Open the map with the filtered layer in Map Viewer Classic. · Click Details and click Content. ·...
Read more >
Convolutional Layer - an overview | ScienceDirect Topics
Convolutional layers are good for feature extraction from images as they deal ... The kernel filters are of the same dimension but with...
Read more >
Different Kinds of Convolutional Filters - Saama Technologies
Different filters are merged or added in separable convolutions in a different way. To get the same effect as a 3×3 convolution, we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found