#include <mil.h>
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Preprocessing/DotMatrixSerial.mim")
#define SMALL_NOISE_RADIUS 1L
#define CHARACTER_MAX_DOT_SPACING 6L
int MosMain(void)
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\nSimpleDilateErode\n\n"));
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilImage,
BinImage;
MIL_INT SizeX, SizeY;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MbufInquire(MilImage, M_SIZE_X, &SizeX);
MbufInquire(MilImage, M_SIZE_Y, &SizeY);
MbufAlloc2d(M_DEFAULT, SizeX, SizeY, 1+M_UNSIGNED, M_IMAGE+M_PROC, &BinImage);
MosPrintf(MIL_TEXT("\nThis program segments the dot matrix\n"));
MosPrintf(MIL_TEXT("characters in the displayed image.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MimBinarize(MilImage, BinImage, M_BIMODAL+M_LESS, M_NULL, M_NULL);
MimErode(BinImage, BinImage, SMALL_NOISE_RADIUS, M_BINARY);
MimDilate(BinImage, BinImage, CHARACTER_MAX_DOT_SPACING/2 + SMALL_NOISE_RADIUS, M_BINARY);
MbufClear(MilImage, 0);
MbufClearCond(MilImage, 255, 0, 255, BinImage, M_EQUAL, 1);
MosPrintf(MIL_TEXT("The dot matrix characters have been segmented using\n"));
MosPrintf(MIL_TEXT("morphological erosion and dilation operations.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n"));
MosGetch();
MbufFree(BinImage);
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}