Home » MaximDL plug-in

MaximDL plug-in

Advertisements

Plug-in modules allow third-party image processing functions to be added into MaxIm DL. Here below you can find an example of home made image processing plug-in that uses Maxim DL document object.

The complete VB.NET solution can be downloaded here

<ComClass(PlugIn.ClassId, PlugIn.InterfaceId, PlugIn.EventsId)> _
Public Class PlugIn
    
#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "62B3DA36-3A4F-4C2F-98D3-7918A900243F"
    Public Const InterfaceId As String = "67BBF9B5-CA78-4967-AD5D-4B30E13831E8"
    Public Const EventsId As String = "E1D5EB33-512D-4326-9FD3-08D53CD05C2A"
#End Region

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub DoModal(ByRef Doc As MaxIm.Document)
        Dim doit As Boolean = False
        Dim Iteration As Integer = My.Settings.Iteration

        Dim Sigma As Single = My.Settings.Sigma
        Dim Radius As Single = My.Settings.Radius
        CreateMyForm(doit, Iteration, Sigma, Radius)
        If doit Then
            If Doc.Color Then
                MedianColor(Doc, Iteration, Sigma, Radius)
            Else
                MedianGrey(Doc, Iteration, Sigma, Radius)
            End If
        End If
        Finalize()
        GC.Collect()

    End Sub

    Public ReadOnly Property Name() As String
        Get
            Return "Double Median Gauss Filter"
        End Get
    End Property
    Sub MedianGrey(ByRef doc As MaxIm.Document, ByRef Iteration As Integer, ByRef Sigma As Single, ByRef Radius As Single)
        Dim Image(,) As Single
        Dim W, H, I, J As Integer
        Dim listvalueD As New List(Of Single)
        Dim listvalueC As New List(Of Single)
        Dim iter As Integer
        For iter = 0 To Iteration
            Image = doc.ImageArray
            W = Image.GetLength(1)
            H = Image.GetLength(0)
            For I = 1 To H - 2
                For J = 1 To W - 2
                    Dim Imval As Single = Image(I, J)
                    listvalueD.Add(Imval)
                    listvalueD.Add(Image(I - 1, J - 1))
                    listvalueD.Add(Image(I - 1, J + 1))
                    listvalueD.Add(Image(I + 1, J - 1))
                    listvalueD.Add(Image(I + 1, J + 1))
                    listvalueD.Sort()
                    listvalueC.Add(Imval)
                    listvalueC.Add(Image(I - 1, J))
                    listvalueC.Add(Image(I, J + 1))
                    listvalueC.Add(Image(I + 1, J))
                    listvalueC.Add(Image(I, J - 1))
                    listvalueC.Sort()
                    Dim a As Double = 1 / (2.4) * (listvalueD(2) + 1.4 * listvalueC(2))
                    If Math.Abs(Imval - a) > Sigma * Math.Sqrt(a) Then
                        Image(I, J) = a
                    End If
                    listvalueD.Clear()
                    listvalueC.Clear()
                Next
            Next
            doc.ImageArray = Image
            If Radius > 0.4 Then
                doc.KernelFilter(MaxIm.KernelFilterType.mxGaussianBlurKF, Radius)
            End If

        Next
        Image = Nothing
        doc.Modified = True

    End Sub
    Sub MedianColor(ByRef doc As MaxIm.Document, ByRef Iteration As Integer, ByRef Sigma As Single, ByRef Radius As Single)
        Dim Image(,,) As Single
        Dim W, H, I, J, K As Integer
        Dim listvalueD As New List(Of Single)
        Dim listvalueC As New List(Of Single)
        Dim iter As Integer
        For iter = 0 To Iteration
            Image = doc.ImageArray
            W = Image.GetLength(2)
            H = Image.GetLength(1)
            For I = 1 To H - 2
                For J = 1 To W - 2
                    Dim Imval As Single = Image(K, I, J)
                    listvalueD.Add(Imval)
                    listvalueD.Add(Image(K, I - 1, J - 1))
                    listvalueD.Add(Image(K, I - 1, J + 1))
                    listvalueD.Add(Image(K, I + 1, J - 1))
                    listvalueD.Add(Image(K, I + 1, J + 1))
                    listvalueD.Sort()
                    listvalueC.Add(Imval)
                    listvalueC.Add(Image(K, I - 1, J))
                    listvalueC.Add(Image(K, I, J + 1))
                    listvalueC.Add(Image(K, I + 1, J))
                    listvalueC.Add(Image(K, I, J - 1))
                    listvalueC.Sort()
                    Dim a As Double = 1 / (2.4) * (listvalueD(2) + 1.4 * listvalueC(2))
                    If Math.Abs(Imval - a) > Sigma * Math.Sqrt(a) Then
                        Image(K, I, J) = a
                    End If
                    listvalueD.Clear()
                    listvalueC.Clear()
                Next
            Next
            doc.ImageArray = Image
            If Radius > 0.4 Then
                doc.KernelFilter(MaxIm.KernelFilterType.mxGaussianBlurKF, Radius)
            End If

        Next
        Image = Nothing
        doc.Modified = True

    End Sub
    Public Sub CreateMyForm(ByRef doit As Boolean, ByRef Iteration As Integer, ByRef Sigma As Single, ByRef Radius As Single)
        ' Create a new instance of the form.
        Dim form1 As New System.Windows.Forms.Form
        form1.Height = 190
        ' Create two buttons to use as the accept and cancel buttons.
        Dim button1 As New System.Windows.Forms.Button()
        Dim button2 As New System.Windows.Forms.Button()
        Dim NumericSigma As New System.Windows.Forms.NumericUpDown()
        Dim NumericIteration As New System.Windows.Forms.NumericUpDown()
        Dim NumericRadius As New System.Windows.Forms.NumericUpDown()
        Dim LabelIteration As New System.Windows.Forms.Label
        Dim LabelSigma As New System.Windows.Forms.Label
        Dim LabelRadius As New System.Windows.Forms.Label

        ' Set the text of button2 to "Cancel".
        button2.Text = "Cancel"
        ' Set the position of the button based on the location of button1.
        button2.Location = New System.Drawing.Point(form1.Width - button2.Width - 10, form1.Height - button2.Height - 40)
        ' Set the text of button1 to "OK".
        button1.Text = "OK"
        ' Set the position of the button on the form.
        button1.Location = New System.Drawing.Point(button2.Left - button1.Width - 10, button2.Top)

        ' Make button1's dialog result OK.
        button1.DialogResult = System.Windows.Forms.DialogResult.OK
        ' Make button2's dialog result Cancel.
        button2.DialogResult = System.Windows.Forms.DialogResult.Cancel
        ' Set the caption bar text of the form.   
        form1.Text = "Double Median Gauss Parameter"


        LabelIteration.Location = New System.Drawing.Point(20, 20)
        LabelIteration.Text = "Iteration"
        NumericIteration.Location = New System.Drawing.Point(LabelIteration.Right + 10, LabelIteration.Top - 5)
        NumericIteration.Width = 100
        NumericIteration.Minimum = 0
        NumericIteration.Maximum = 5
        NumericIteration.Increment = 1
        NumericIteration.Value = Iteration



        LabelSigma.Location = New System.Drawing.Point(LabelIteration.Left, LabelIteration.Bottom + 10)
        LabelSigma.Text = "Sigma"
        NumericSigma.Location = New System.Drawing.Point(LabelSigma.Right + 10, LabelSigma.Top - 5)
        NumericSigma.Width = 100
        NumericSigma.Minimum = 1
        NumericSigma.Maximum = 5
        NumericSigma.DecimalPlaces = 1
        NumericSigma.Increment = 0.1
        NumericSigma.Value = Sigma


        LabelRadius.Location = New System.Drawing.Point(LabelIteration.Left, LabelSigma.Bottom + 10)
        LabelRadius.Text = "G.F. Radius"
        NumericRadius.Location = New System.Drawing.Point(LabelRadius.Right + 10, LabelRadius.Top - 5)
        NumericRadius.Width = 100
        NumericRadius.Minimum = 0
        NumericRadius.Maximum = 1.5
        NumericRadius.DecimalPlaces = 1
        NumericRadius.Increment = 0.1
        NumericRadius.Value = Radius


        form1.Controls.Add(LabelIteration)
        form1.Controls.Add(NumericIteration)

        form1.Controls.Add(LabelSigma)
        form1.Controls.Add(NumericSigma)

        form1.Controls.Add(LabelRadius)
        form1.Controls.Add(NumericRadius)

        ' Define the border style of the form to a dialog box.
        form1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        ' Set the accept button of the form to button1.
        form1.AcceptButton = button1
        ' Set the cancel button of the form to button2.
        form1.CancelButton = button2
        ' Set the start position of the form to the center of the screen.
        form1.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen

        ' Add button1 to the form.
        form1.Controls.Add(button1)
        ' Add button2 to the form.
        form1.Controls.Add(button2)



        ' Display the form as a modal dialog box.
        form1.ShowDialog()

        ' Determine if the OK button was clicked on the dialog box.
        If form1.DialogResult = System.Windows.Forms.DialogResult.OK Then
            My.Settings.Radius = NumericRadius.Value
            My.Settings.Sigma = NumericSigma.Value
            My.Settings.Iteration = NumericIteration.Value
            My.Settings.Save()
            doit = True
            Radius = My.Settings.Radius
            Sigma = My.Settings.Sigma
            Iteration = My.Settings.Iteration
            form1.Dispose()

        Else
            doit = False
            form1.Dispose()
        End If
    End Sub 'CreateMyForm 
End Class
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: