#include <mil.h>
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("BaboonMono.mim")
#define ZOOM_VALUE 2
#define KERNEL_WIDTH 3L
#define KERNEL_HEIGHT 3L
#define KERNEL_DEPTH 8L
#define KERNEL_NORMALIZATION 16L
unsigned char KernelData[KERNEL_HEIGHT][KERNEL_WIDTH] =
{ {1, 2, 1},
{2, 4, 2},
{1, 2, 1}
};
#define NB_LOOP 100
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilDisplayImage,
MilImage,
MilKernel;
long n;
MIL_DOUBLE Time;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem,
&MilDisplay, M_NULL, M_NULL);
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
MbufRestore(IMAGE_FILE, MilSystem, &MilDisplayImage);
MdispZoom(MilDisplay, ZOOM_VALUE, ZOOM_VALUE);
MdispSelect(MilDisplay, MilDisplayImage);
MosPrintf(MIL_TEXT("\nIMAGE PROCESSING:\n"));
MosPrintf(MIL_TEXT("-----------------\n\n"));
MosPrintf(MIL_TEXT("This program performs a convolution on the displayed image.\n"));
MosPrintf(MIL_TEXT("It uses a custom smoothing kernel.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufAlloc2d(MilSystem, KERNEL_WIDTH, KERNEL_HEIGHT,
KERNEL_DEPTH+M_UNSIGNED, M_KERNEL, &MilKernel);
MbufPut(MilKernel,KernelData);
MbufControlNeighborhood(MilKernel,M_NORMALIZATION_FACTOR,KERNEL_NORMALIZATION);
MimConvolve(MilImage, MilDisplayImage, MilKernel);
MbufControlNeighborhood(MilKernel, M_OVERSCAN, M_DISABLE);
MimConvolve(MilDisplayImage, MilImage, MilKernel);
MappTimer(M_DEFAULT, M_TIMER_RESET+M_SYNCHRONOUS, M_NULL);
for (n= 0; n < NB_LOOP; n++)
MimConvolve(MilDisplayImage, MilImage, MilKernel);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &Time);
MosPrintf(MIL_TEXT("Convolve time: %.3f ms.\n"), Time*1000/NB_LOOP);
MosPrintf(MIL_TEXT("Press <Enter> to terminate.\n"));
MosGetch();
MbufFree(MilKernel);
MbufFree(MilImage);
MbufFree(MilDisplayImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}