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:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 typenapari.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 thewidget_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: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.