|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +Extract blobs (plugin example) |
| 5 | +============================== |
| 6 | +
|
| 7 | +This is a simple example of a DataLab image processing plugin. |
| 8 | +
|
| 9 | +It adds a new menu entry in "Plugins" menu, with a sub-menu "Extract blobs (example)". |
| 10 | +This sub-menu contains two actions, "Preprocess image" and "Detect blobs". |
| 11 | +
|
| 12 | +.. note:: |
| 13 | +
|
| 14 | + This plugin is not installed by default. To install it, copy this file to |
| 15 | + your DataLab plugins directory (see `DataLab documentation |
| 16 | + <https://cdlapp.readthedocs.io/en/latest/features/general/plugins.html>`_). |
| 17 | +""" |
| 18 | + |
| 19 | +import cdl.param |
| 20 | +import cdl.plugins |
| 21 | + |
| 22 | + |
| 23 | +class ExtractBlobs(cdl.plugins.PluginBase): |
| 24 | + """DataLab Example Plugin""" |
| 25 | + |
| 26 | + PLUGIN_INFO = cdl.plugins.PluginInfo( |
| 27 | + name="Extract blobs (example)", |
| 28 | + version="1.0.0", |
| 29 | + description="This is an example plugin", |
| 30 | + ) |
| 31 | + |
| 32 | + def preprocess(self) -> None: |
| 33 | + """Preprocess image""" |
| 34 | + panel = self.imagepanel |
| 35 | + param = cdl.param.BinningParam.create(binning_x=2, binning_y=2) |
| 36 | + panel.processor.compute_binning(param) |
| 37 | + panel.processor.compute_moving_median(cdl.param.MovingMedianParam.create(n=5)) |
| 38 | + |
| 39 | + def detect_blobs(self) -> None: |
| 40 | + """Detect circular blobs""" |
| 41 | + panel = self.imagepanel |
| 42 | + param = cdl.param.BlobOpenCVParam() |
| 43 | + param.filter_by_circularity = True |
| 44 | + param.min_circularity = 0.8 |
| 45 | + param.max_circularity = 1.0 |
| 46 | + panel.processor.compute_blob_opencv(param) |
| 47 | + |
| 48 | + def create_actions(self) -> None: |
| 49 | + """Create actions""" |
| 50 | + acth = self.imagepanel.acthandler |
| 51 | + with acth.new_menu(self.PLUGIN_INFO.name): |
| 52 | + acth.new_action("Preprocess image", triggered=self.preprocess) |
| 53 | + acth.new_action("Detect circular blobs", triggered=self.detect_blobs) |
0 commit comments