CsatiZoltan / GrainSegmentation

Identification of individual grains in microscopic images
GNU General Public License v3.0
6 stars 3 forks source link

ImagePy plugin using an existing class #7

Closed CsatiZoltan closed 4 years ago

CsatiZoltan commented 4 years ago

Reproducing the menu structure for an ImagePy plugin works successfully if I directly put the implementation to the run method. Actually, in the existing projects I found (seaice, skimg, ITK, IBook), the implementation of an algorithm is always in the same file (i.e. in the plugin file: xxx_plgs.py) as the classes containing the run method. E.g. the showice function is in result_plgs.py, just as the run methods of the classes inheriting from the Simple class.

In my case, the algorithms can be found in the GrainSegmentation class in grain_segmentation.py. So what I want is:

CsatiZoltan commented 4 years ago

Perhaps simple functions written to the same file where the grain segmentation ImagePy plugin is implemented makes it easier to manage. Anyway, I don't intend to use very complex image processing algorithms in the future. Another solution could be to overwrite the constructor of the Filter class so that I can pass the GrainSegmentation object.

yxdragon commented 4 years ago

In fact any template, such as (Tool, Filter, Simple...) has one format "start". If in java, it should be a super interface, but python is flexable, So i did not write a BasePlugin just has a start method. May be Free is the simplest plugin, just has a run method.

about the pipeline, ImagePy has many manager, you can see imagepy.core.manager. ImageManager can give all the images opened, and can get the top image(current). Filter adn Simple 's run, the ips parameter is the top image (which pass by the Filter and Simple 's baseclass). And there is another parameter. para = {'im':None}, view = [('img', 'current', 'image')]. The dialog would let you to select a image. return a string, Then you can use ImageManager.get(name) to get the ips object.

CsatiZoltan commented 4 years ago

After understanding a bit more on the working of ImagePy, I opted for the following (at least for now). Since ImagePy works best with manipulating the open images, I try to minimize the use of custom data. It is intuitive that the currently selected image is what the user wants to perform manipulations on. However, in some cases, it is necessary to deal with custom data. For that, I use a class, initialized in the plugin module. This exposes the class object to be global within that module. I can then dynamically add and fetch attributes. It will be created according to my post.

ImagePy is a very useful tool but it would need more documentation for the input arguments of the methods. Even browsing the source code, it's often difficult to understand.