Menu

Python, filtering

Navigation
loading images Contents image registration

Filtering

The pymia.filter function transparently distinguishes between 2D and 3D images. Filters are specified as strings like they are given on the mia-2dimagefilter and mia-3dimagefilter command line.

Filters can be run one at a time, or as a pipeline. To run a single filter, e.g. a median filter of half filter width 3 on an image input run

filtered = pymia.filter(input, "median:w=3")

To run a filter chain, e.g. the above median, followed by a mean-least-variance filter with a filter width parameter 5, provide the filters as a list:

filtered = pymia.filter(input, ["median:w=3", "mlv:w=5"])

Note that the filters function converts the input to the internal MIA image format, creates and runs the filters, and then converts the images back to numpy arrays. Therefore, for performance reasons, it is best to run the filter chains instead of one filter at a time.

In order to avoid re-creating filters one can enable the filter cache by calling

pymia.set_filter_plugin_cache(True)

Then, filters with the same description are re-used in subsequent calls to the pymia.filter function. The filters in MIA normally work like functions, i.e. no state changes when it is called. However, in some rare cases, when external data is loaded by means of a filter parameter, this may actually not work like expected (cf. [tickets:#134]).


Related

Tickets-mia: #134
Wiki: Python, image registration
Wiki: Python, loading images
Wiki: Using mia from Python

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.