In Tutorial 05 it was shown how to develop a simple plug-in for image processing using Marvin Framework. The advantage of using a plug-in architecture is the fact that new algorithms can be delivered to applications that use Marvin totally independent of the releases of the framework. Moreover, developers can easily integrate their algorithms with tools that use Marvin like the image editor MarvinEditor.

Many algorithms have parameters whose settings control important aspects of their behaviour. This tutorial demonstrates how to add parameters to plug-ins using Marvin Framework. In order to address this issue in practice, a plug-in that just access user/developer specified parameters is implemented.

Plug-in

The source code below presents a skeleton for an image processing plug-in.

package image.plugin.gui; 

import marvin.gui.MarvinAttributesPanel; 
import marvin.image.MarvinImage; 
import marvin.image.MarvinImageMask; 
import marvin.plugin.MarvinAbstractImagePlugin; 
import marvin.util.MarvinAttributes; 

public class GuiPlugin extends MarvinAbstractImagePlugin{

    public void load(){ 
    } 

    public MarvinAttributesPanel getAttributesPanel(){ 
    } 
     
    public void process 
    ( 
        MarvinImage imageIn,  
        MarvinImage imageOut, 
        MarvinAttributes attributesOut, 
        MarvinImageMask mask,  
        boolean previewMode 
    ) 
    { 
    } 
} 

The class MarvinAttributes is used to manage plug-in attributes or parameters. MarvinAbstractImagePlugin has an object of this class and provides the methods getAttribute() and setAttribute() to manipulate it. In order to define a set of the plug-in attributes and their default values, the following lines of source code are added into the method load()
public void load(){ 
    setAttribute("red", 10); 
    setAttribute("green", 50); 
    setAttribute("blue", 125); 
    setAttribute("filter", "option 1"); 
    setAttribute("intensity", 0); 
    setAttribute("checkbox1", false); 
    setAttribute("matrix", new double[][]{{1.0,2.0},{3.0,4.0},{5.0,6.0}}); 
}

These parameters have to be accessed before processing the image. Therefore, in the method process(), the value of any parameter can be requested using getAttribute(). In this example, the method process() just prints the parameters values on the console, as shown below.

public void process 
( 
    MarvinImage imageIn,  
    MarvinImage imageOut, 
    MarvinAttributes attributesOut, 
    MarvinImageMask mask,  
    boolean previewMode 
) 
{ 
    System.out.println("red:"+(Integer)getAttribute("red")); 
    System.out.println("green:"+(Integer)getAttribute("green")); 
    System.out.println("blue:"+(Integer)getAttribute("blue")); 
    System.out.println("filter:"+(String)getAttribute("filter")); 
    System.out.println("intensity:"+(Integer)getAttribute("intensity")); 
    System.out.println("checkbox checked:"+(Boolean)getAttribute("checkbox1")); 
    System.out.println("\nMatrix:"); 
         
    double[][] matrix = (double[][])getAttribute("matrix"); 
    for(int i=0; i<matrix.length; i++){ 
        for(int j=0; j<matrix[i].length; j++){ 
            System.out.print("["+matrix[i][j]+"]"); 
        } 
        System.out.println(""); 
    } 
}

Application

In order to test the GuiPlugin a simple application was created, as shown below:

public class AppGuiPlugin{ 
    public static void main(String args[]){ 
        GuiPlugin plugin = new GuiPlugin(); 
        plugin.load(); 
        plugin.process(null, null);
    } 
}

When executed this applications prints the default value of each attribute:

red:10 
green:50 
blue:125 
filter:option 1 
intensity:0 
checkbox checked:false 

Matrix: 
[1.0][2.0] 
[3.0][4.0] 
[5.0][6.0]