Python plugin does not show up in ImagePy

I want to create a plugin of class Filter for ImagePy. First, I go through the examples. However, putting that .py file to the menus/Plugins directory has no effect. When I open ImagePy, the menu does not show up. This is strange because the plugins of types Macros, Markdown and Workflow appear in the menu. I tried both the standalone Windows version of ImagePy and the one from the source: same behaviour.

  1. the file should be xxx_plg.py or xxx_plgs.py
  2. make sure the code is right.
    the plugin file can not run self (may alert no model named xxx, it is ok). but make sure there is no syntax error, And when ImagePy start, if some plugin is not loaded successfully, a white log window would be poped

tips:

It seems that you write your plugins, then put it in menus’s subfolder to run, It is OK, but if you are writting a plugins, the best way is:

  1. clone the imagepy repo
  2. open it in an IDE, such as sublime text, pycharm
  3. add your plugin file, and edit.
  4. run the main.py to start imagepy, then test and debug.
    if you are in development environment, please pip uninstall imagepy, else the main file would import from pip environment, not the development one

if your working is not secret, you can build a git repo, I can review or give pr!

Thanks for the debugging tip, I tried it. In response to your answer:

  1. Now I renamed the plugin to Gaussian_plg.py.
  2. The code is right because it’s taken from the documentation.

I get the following plugin loading error:

Some plugin may be not loaded, but not affect others!
>>> menus\Plugins                                     Gaussian_plg.py     module 'imagepy.menus.Plugins.Gaussian_plg' has no attribute 'Plugin'
Some plugin may be not loaded, but not affect others!
>>> plugins\Image-Py_IBook\menus\IBook\Image Referencedimage_plgs.py       cannot import name 'imread' from 'scipy.misc' (C:\Programok\Anaconda3\lib\site-packages\scipy\misc\__init__.py)

By the way, I have scipy installed so I don’t know why I get the second plugin loading error.

I plan to create a repo once I advance a bit…

I am sorry, I lost some detail in the demoplugin’s document. I would add it soon.

That 's:

  1. if your plugin file has only one plugin, you need name the class as “Plugin(Filter)”
  2. if the file has multi plugins, such as Gauss(Filter), Uniform(Filter)…, in th end, you need add
    plgs = [Gauss, Uniform]

Because the document’s code is from https://github.com/Image-Py/imagepy/blob/master/imagepy/menus/Process/Filters/classic_plgs.py, I copy one plugin from a multi-plugins file, So… I am so sorry.

the second error is because, scipy.misc is outdated, and I did not review the IBook intime. I would update it later. you can replace with skimage.io.imread.

  1. OK, renaming the class to Plugin solves the problem. It would be nice to update the documentation with it. For completeness, here is the Python file Gaussian_plg.py:
from imagepy.core.engine import Filter
from scipy.ndimage import gaussian_filter

class Plugin(Filter):
    title = 'Gaussian Demo'
    note = ['all', 'auto_msk', 'auto_snap','preview']
    para = {'sigma':2}
    view = [(float, 'sigma', (0,30), 1,  'sigma', 'pix')]
    
    def run(self, ips, snap, img, para = None):
        gaussian_filter(snap, para['sigma'], output=img)
  1. Yes, I read in the tutorial that I need to append plgs = [plugin_1, plugin2, ...] to the end of the file. My current plugin file consists of only one file.


Concerning the first point, I realized that there is another solution: I don’t need to give the class the name Plugin if I append it with a list called plgs (here comes Gaussian2_plg.py:):

from imagepy.core.engine import Filter
from scipy.ndimage import gaussian_filter

class Gaussian(Filter):
    title = 'Gaussian Demo'
    note = ['all', 'auto_msk', 'auto_snap','preview']
    para = {'sigma':2}
    view = [(float, 'sigma', (0,30), 1,  'sigma', 'pix')]
    
    def run(self, ips, snap, img, para = None):
        gaussian_filter(snap, para['sigma'], output=img)

plgs = [Gaussian]

the parser would scan all the menus’s subfolder, find the _plg.py, _plgs.py. Then try to load the Plugin Class, if not found, load the plgs. the plgs field can define multiplugins’ order. and you can also add ‘-’ in the plgs, it would parse as split line on the menu.

See the repo here. You are invited. See the first issue.

1 Like

Sorry, I am placed in a medical isolation. Because one of my friend is infected with WuHan lung virus. I am OK now, but have no computer these days.

There is nothing to feel sorry about. Your health is more important than any image segmentation project!

1 Like

:+1: :+1: :heart:

@yxdragon The first publicly known case of the virus was confirmed yesterday here in Wisconsin. I wish you and yours the very best of luck in getting through it!

I am ok, thanks. and @ZCs we can start the work.

Please join to my newly created Gitter room:
Gitter