using System;
using System.Collections.Generic;
using System.Text;
using Matrox.MatroxImagingLibrary;
namespace MImConvolve
{
class Program
{
private const string IMAGE_FILE = MIL.M_IMAGE_PATH + "BaboonMono.mim";
private const int ZOOM_VALUE = 2;
private const int KERNEL_WIDTH = 3;
private const int KERNEL_HEIGHT = 3;
private const int KERNEL_DEPTH = 8;
private const int KERNEL_NORMALIZATION = 16;
private static readonly byte[,] KernelData = new byte[KERNEL_HEIGHT, KERNEL_WIDTH] { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } };
private const int NB_LOOP = 100;
static void Main(string[] args)
{
MIL_ID MilApplication = MIL.M_NULL;
MIL_ID MilSystem = MIL.M_NULL;
MIL_ID MilDisplay = MIL.M_NULL;
MIL_ID MilDisplayImage = MIL.M_NULL;
MIL_ID MilImage = MIL.M_NULL;
MIL_ID MilKernel = MIL.M_NULL;
int n = 0;
double Time = 0.0;
MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);
MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage);
MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilDisplayImage);
MIL.MdispZoom(MilDisplay, ZOOM_VALUE, ZOOM_VALUE);
MIL.MdispSelect(MilDisplay, MilDisplayImage);
Console.Write("\nIMAGE PROCESSING:\n");
Console.Write("-----------------\n\n");
Console.Write("This program performs a convolution on the displayed image.\n");
Console.Write("It uses a custom smoothing kernel.\n");
Console.Write("Press <Enter> to continue.\n\n");
Console.ReadKey();
MIL.MbufAlloc2d(MilSystem, KERNEL_WIDTH, KERNEL_HEIGHT, KERNEL_DEPTH + MIL.M_UNSIGNED, MIL.M_KERNEL, ref 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, MIL.M_NULL);
for (n = 0; n < NB_LOOP; n++)
{
MIL.MimConvolve(MilDisplayImage, MilImage, MilKernel);
}
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref Time);
Console.Write("Convolve time: {0:0.000} ms.\n", Time * 1000 / NB_LOOP);
Console.Write("Press <Enter> to terminate.\n");
Console.ReadKey();
MIL.MbufFree(MilKernel);
MIL.MbufFree(MilImage);
MIL.MbufFree(MilDisplayImage);
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
}
}
}