#include <mil.h>
void GraphProjection (MIL_ID MilSystem, MIL_ID MilDisplay, MIL_CONST_TEXT_PTR Filename);
#define IMAGE_WAFER M_IMAGE_PATH MIL_TEXT("Wafer.mim")
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("Projection\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("This program demonstrates how to use the projection\n")
MIL_TEXT("primitive with various operators.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Modules used: application, system, display, buffer,\n")
MIL_TEXT("graphic, image processing.\n\n"));
}
int MosMain(void)
{
PrintHeader();
MIL_ID MilApplication,
MilSystem,
MilDisplay;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, M_NULL,M_NULL, M_NULL);
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_WINDOWED, &MilDisplay);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
GraphProjection(MilSystem,MilDisplay,IMAGE_WAFER);
MdispFree(MilDisplay);
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
return 0;
}
void GraphProjection(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_CONST_TEXT_PTR Filename)
{
MIL_ID MilImage,
MilOverlayImage,
MilGraphicList,
MilSubImage00,
MilSubImage01,
MilOverlaySubImage,
MilResultId;
MIL_INT Type,SizeX, SizeY, OverlayClearColor;
MbufDiskInquire(Filename,M_SIZE_X,&SizeX);
MbufDiskInquire(Filename,M_SIZE_Y,&SizeY);
MbufDiskInquire(Filename,M_TYPE, &Type);
const MIL_INT GraphSizeY = 256 + 50;
MbufAlloc2d(MilSystem, SizeX, SizeY + GraphSizeY,
Type, M_IMAGE+M_PROC+M_DISP, &MilImage);
MbufClear(MilImage, 0L);
MdispSelect (MilDisplay, MilImage);
MdispInquire(MilDisplay, M_TRANSPARENT_COLOR, &OverlayClearColor);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MbufClear(MilOverlayImage, (MIL_DOUBLE)OverlayClearColor);
MgraAllocList(MilSystem, M_DEFAULT, &MilGraphicList);
MbufChild2d(MilImage, 0L, 0L, SizeX, SizeY, &MilSubImage00);
MbufChild2d(MilImage, 0L, SizeY, SizeX, GraphSizeY, &MilSubImage01);
MbufChild2d(MilOverlayImage, 0L, SizeY, SizeX, GraphSizeY, &MilOverlaySubImage);
MimAllocResult(MilSystem, SizeX, M_PROJ_LIST, &MilResultId);
MIL_DOUBLE* ColumnIndexes = new MIL_DOUBLE[SizeX];
MIL_DOUBLE* ProjectedValues = new MIL_DOUBLE[SizeX];
for (MIL_INT ii = 0; ii < SizeX; ++ii)
ColumnIndexes[ii] = (MIL_DOUBLE)ii;
MbufLoad(Filename, MilSubImage00);
MbufClear(MilSubImage01, 0);
const MIL_INT NumberOfOperations = 4;
const MIL_INT64 Operations[4] = {M_SUM, M_MAX, M_MIN, M_MEDIAN};
const MIL_INT64 OperationColors[4] = {M_COLOR_LIGHT_BLUE, M_COLOR_GREEN, M_COLOR_RED, M_COLOR_YELLOW};
MIL_CONST_TEXT_PTR OperationString[4] = {MIL_TEXT("Average"),
MIL_TEXT("Maximum"),
MIL_TEXT("Minimum"),
MIL_TEXT("Median")};
for (MIL_INT Op = 0; Op < NumberOfOperations; ++Op)
{
MimProjection(MilSubImage00, MilResultId, M_0_DEGREE, Operations[Op], M_NULL);
MimGetResult(MilResultId, M_VALUE + M_TYPE_DOUBLE, ProjectedValues);
if (Operations[Op] == M_SUM)
{
for (MIL_INT ii = 0; ii < SizeX; ++ii)
ProjectedValues[ii] = GraphSizeY - (ProjectedValues[ii] / (MIL_DOUBLE)SizeY);
}
else
{
for (MIL_INT ii = 0; ii < SizeX; ++ii)
ProjectedValues[ii] = GraphSizeY - ProjectedValues[ii];
}
MgraColor(M_DEFAULT, (MIL_DOUBLE)OperationColors[Op]);
MgraLines(M_DEFAULT, MilGraphicList, SizeX, ColumnIndexes, ProjectedValues, M_NULL, M_NULL, M_POLYLINE);
MgraText(M_DEFAULT,MilOverlaySubImage,SizeX - 60, 14 * (1 + Op), OperationString[Op]);
}
MgraDraw(MilGraphicList, MilOverlaySubImage, M_DEFAULT);
MgraText(M_DEFAULT,MilSubImage00,0,0,MIL_TEXT("Source image"));
MgraText(M_DEFAULT,MilSubImage01,0,0,MIL_TEXT("Projections"));
MosPrintf(MIL_TEXT("Several projections of an image have been performed.\n")
MIL_TEXT("The projection results are drawn as follows:\n")
MIL_TEXT("\tThe average of each column has been drawn in light blue.\n")
MIL_TEXT("\tThe maximum of each column has been drawn in green.\n")
MIL_TEXT("\tThe minimum of each column has been drawn in red.\n")
MIL_TEXT("\tThe median of each column has been drawn in yellow.\n"));
MosPrintf(MIL_TEXT("\nPress <Enter> to end.\n\n"));
MosGetch();
MbufFree(MilOverlaySubImage);
MbufFree(MilSubImage00);
MbufFree(MilSubImage01);
MbufFree(MilImage);
MimFree(MilResultId);
MgraFree(MilGraphicList);
delete[] ProjectedValues;
delete[] ColumnIndexes;
}