'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MImConvolve
Friend Class Program
Private Const IMAGE_FILE As String = MIL.M_IMAGE_PATH & "BaboonMono.mim"
Private Const ZOOM_VALUE As Integer = 2
Private Const KERNEL_WIDTH As Integer = 3
Private Const KERNEL_HEIGHT As Integer = 3
Private Const KERNEL_DEPTH As Integer = 8
Private Const KERNEL_NORMALIZATION As Integer = 16
Private Shared ReadOnly KernelData(,) As Byte = {{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}
Private Const NB_LOOP As Integer = 100
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilDisplayImage As MIL_ID = MIL.M_NULL
Dim MilImage As MIL_ID = MIL.M_NULL
Dim MilKernel As MIL_ID = MIL.M_NULL
Dim n As Integer = 0
Dim Time As Double = 0.0
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilImage)
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilDisplayImage)
MIL.MdispZoom(MilDisplay, ZOOM_VALUE, ZOOM_VALUE)
MIL.MdispSelect(MilDisplay, MilDisplayImage)
Console.Write(Constants.vbLf + "IMAGE PROCESSING:" + Constants.vbLf)
Console.Write("-----------------" + Constants.vbLf + Constants.vbLf)
Console.Write("This program performs a convolution on the displayed image." + Constants.vbLf)
Console.Write("It uses a custom smoothing kernel." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MbufAlloc2d(MilSystem, KERNEL_WIDTH, KERNEL_HEIGHT, KERNEL_DEPTH + MIL.M_UNSIGNED, MIL.M_KERNEL, MilKernel)
MIL.MbufPut(MilKernel, KernelData)
MIL.MbufControlNeighborhood(MilKernel, MIL.M_NORMALIZATION_FACTOR, KERNEL_NORMALIZATION)
MIL.MimConvolve(MilImage, MilDisplayImage, MilKernel)
MIL.MbufControlNeighborhood(MilKernel, MIL.M_OVERSCAN, MIL.M_DISABLE)
MIL.MimConvolve(MilDisplayImage, MilImage, MilKernel)
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, CType(MIL.M_NULL, IntPtr))
For n = 0 To NB_LOOP - 1
MIL.MimConvolve(MilDisplayImage, MilImage, MilKernel)
Next n
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, Time)
Console.Write("Convolve time: {0:0.000} ms." + Constants.vbLf, Time * 1000.0 / NB_LOOP)
Console.Write("Press <Enter> to terminate." + Constants.vbLf)
Console.ReadKey()
MIL.MbufFree(MilKernel)
MIL.MbufFree(MilImage)
MIL.MbufFree(MilDisplayImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Class
End Namespace