#include <mil.h>
#define CONTOUR_IMAGE M_IMAGE_PATH MIL_TEXT("Seals.mim")
#define CONTOUR_MAX_RESULTS 100
#define CONTOUR_MAXIMUM_ELONGATION 0.8
#define CONTOUR_DRAW_COLOR M_COLOR_GREEN
#define CONTOUR_LABEL_COLOR M_COLOR_RED
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilImage,
GraphicList,
MilEdgeContext,
MilEdgeResult;
MIL_DOUBLE EdgeDrawColor = CONTOUR_DRAW_COLOR,
LabelDrawColor = CONTOUR_LABEL_COLOR;
MIL_INT NumEdgeFound = 0L,
NumResults = 0L,
i;
MIL_DOUBLE MeanFeretDiameter[CONTOUR_MAX_RESULTS];
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MbufRestore(CONTOUR_IMAGE, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MgraAllocList(MilSystem, M_DEFAULT, &GraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList);
MosPrintf(MIL_TEXT("\nEDGE MODULE:\n"));
MosPrintf(MIL_TEXT("------------\n\n"));
MosPrintf(MIL_TEXT("This program determines the outer seal diameters ")
MIL_TEXT("in the displayed image \n"));
MosPrintf(MIL_TEXT("by detecting and analyzing contours ")
MIL_TEXT("with the Edge Finder module.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MedgeAlloc(MilSystem, M_CONTOUR, M_DEFAULT, &MilEdgeContext);
MedgeAllocResult(MilSystem, M_DEFAULT, &MilEdgeResult);
MedgeControl(MilEdgeContext, M_MOMENT_ELONGATION, M_ENABLE);
MedgeControl(MilEdgeContext, M_FERET_MEAN_DIAMETER+M_SORT1_DOWN, M_ENABLE);
MedgeCalculate(MilEdgeContext, MilImage, M_NULL, M_NULL, M_NULL, MilEdgeResult,
M_DEFAULT);
MedgeGetResult(MilEdgeResult, M_DEFAULT, M_NUMBER_OF_CHAINS+M_TYPE_MIL_INT,
&NumEdgeFound, M_NULL);
MgraColor(M_DEFAULT, EdgeDrawColor);
MedgeDraw(M_DEFAULT, MilEdgeResult, GraphicList, M_DRAW_EDGES, M_DEFAULT,
M_DEFAULT);
MosPrintf(MIL_TEXT("%d edges were found in the image.\n"), NumEdgeFound);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MedgeSelect(MilEdgeResult, M_EXCLUDE, M_MOMENT_ELONGATION,
M_LESS, CONTOUR_MAXIMUM_ELONGATION, M_NULL);
MedgeSelect(MilEdgeResult, M_EXCLUDE, M_INCLUDED_EDGES, M_INSIDE_BOX, M_NULL, M_NULL);
MgraClear(M_DEFAULT, GraphicList);
MgraColor(M_DEFAULT, EdgeDrawColor);
MedgeDraw(M_DEFAULT, MilEdgeResult, GraphicList, M_DRAW_EDGES, M_DEFAULT,
M_DEFAULT);
MosPrintf(MIL_TEXT("Elongated edges and inner edges of each seal were removed.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MedgeGetResult(MilEdgeResult, M_DEFAULT, M_NUMBER_OF_CHAINS+M_TYPE_MIL_INT,
&NumResults, M_NULL);
if ( (NumResults >= 1) && (NumResults <= CONTOUR_MAX_RESULTS) )
{
MgraColor(M_DEFAULT, LabelDrawColor);
MedgeDraw(M_DEFAULT, MilEdgeResult, GraphicList, M_DRAW_INDEX,
M_DEFAULT, M_DEFAULT);
MedgeGetResult(MilEdgeResult, M_DEFAULT, M_FERET_MEAN_DIAMETER,
MeanFeretDiameter, M_NULL);
MosPrintf(MIL_TEXT("Mean diameter of the %ld outer edges are:\n\n"), NumResults);
MosPrintf(MIL_TEXT("Index Mean diameter \n"));
for (i=0; i<NumResults; i++)
{
MosPrintf(MIL_TEXT("%-11d%-13.2f\n"), i, MeanFeretDiameter[i]);
}
}
else
{
MosPrintf(MIL_TEXT("Edges have not been found or the number of ")
MIL_TEXT("found edges is greater than\n"));
MosPrintf(MIL_TEXT("the specified maximum number of edges !\n\n"));
}
MosPrintf(MIL_TEXT("\nPress <Enter> to end.\n"));
MosGetch();
MgraFree(GraphicList);
MbufFree(MilImage);
MedgeFree(MilEdgeContext);
MedgeFree(MilEdgeResult);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}