#include <mil.h>
#define EXAMPLE_IMAGE_PATH M_IMAGE_PATH MIL_TEXT("Seals.mim")
#define MIN_BLOB_RADIUS 1L
#define LOWPARAM_THRESHOLD 80
#define VECTOR_FIELD_STRIDE 2
#define VECTOR_FIELD_SCALE 0.03
#define DISP_ZOOM_FACTOR 4
#define DISP_PAN_OFFSET_X 310
#define DISP_PAN_OFFSET_Y 80
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilImage,
DerivativeX,
DerivativeY,
MilMagnitude,
MilMask;
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("MgraVectors\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("The image gradient is calculated and the gradient \n")
MIL_TEXT("vector field along the objects' contours is displayed.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Buffer, Display, Graphics, Image Processing\n\n")
);
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MbufRestore(EXAMPLE_IMAGE_PATH, MilSystem, &MilImage);
MIL_INT SizeX = MbufInquire(MilImage, M_SIZE_X, M_NULL);
MIL_INT SizeY = MbufInquire(MilImage, M_SIZE_Y, M_NULL);
MbufAlloc2d(MilSystem, SizeX, SizeY, 32 + M_FLOAT, M_IMAGE + M_PROC, &DerivativeX);
MbufAlloc2d(MilSystem, SizeX, SizeY, 32 + M_FLOAT, M_IMAGE + M_PROC, &DerivativeY);
MbufAlloc2d(MilSystem, SizeX, SizeY, 32 + M_FLOAT, M_IMAGE + M_PROC, &MilMagnitude);
MbufAlloc2d(MilSystem, SizeX, SizeY, 1L, M_IMAGE + M_PROC, &MilMask);
MimConvolve(MilImage, MilImage, M_SMOOTH);
MimConvolve(MilImage, DerivativeX, M_SOBEL_X);
MimConvolve(MilImage, DerivativeY, M_SOBEL_Y);
MimTransform(DerivativeX, DerivativeY, MilMagnitude, M_NULL, M_POLAR, M_DEFAULT);
MimBinarize(MilMagnitude, MilMask, M_FIXED + M_GREATER, LOWPARAM_THRESHOLD, M_NULL);
MimOpen(MilMask, MilMask, MIN_BLOB_RADIUS, M_BINARY);
MimClose(MilMask, MilMask, MIN_BLOB_RADIUS, M_BINARY);
MbufClearCond(DerivativeX, 0, M_NULL, M_NULL, MilMask, M_EQUAL, 0);
MbufClearCond(DerivativeY, 0, M_NULL, M_NULL, MilMask, M_EQUAL, 0);
MIL_ID MilGraphicList = MgraAllocList(MilSystem, M_DEFAULT, M_NULL);
MIL_ID GraContextId = MgraAlloc(MilSystem, M_NULL);
MgraColor(GraContextId, M_COLOR_RED);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, MilGraphicList);
MgraVectorsGrid(GraContextId,
MilGraphicList,
DerivativeX,
DerivativeY,
VECTOR_FIELD_STRIDE,
M_ABSOLUTE,
VECTOR_FIELD_SCALE,
M_SKIP_NULL_VECTORS |
M_FIXED_LENGTH_ARROWHEADS);
MdispControl(MilDisplay, M_VIEW_MODE, M_AUTO_SCALE);
MdispSelect(MilDisplay, MilImage);
MdispZoom(MilDisplay, DISP_ZOOM_FACTOR, DISP_ZOOM_FACTOR);
MdispPan(MilDisplay, DISP_PAN_OFFSET_X, DISP_PAN_OFFSET_Y);
MosPrintf(MIL_TEXT("Press <ENTER> to end"));
MosGetchar();
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, M_NULL);
MbufFree(MilImage);
MbufFree(DerivativeX);
MbufFree(DerivativeY);
MbufFree(MilMagnitude);
MbufFree(MilMask);
MgraFree(MilGraphicList);
MgraFree(GraContextId);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}