#include <mil.h>
#include <stdlib.h>
#define NUM_IMAGES_TO_REGISTER 3
#define IMAGE_FILES_SOURCE M_IMAGE_PATH MIL_TEXT("CircuitBoardPart%d.mim")
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilGraphicList,
MilSourceImages
[NUM_IMAGES_TO_REGISTER],
MilMosaicImage = M_NULL,
MilRegContext,
MilRegResult;
MIL_INT i;
MIL_INT Result;
MIL_INT MosaicSizeX,
MosaicSizeY;
MIL_INT MosaicSizeBand,
MosaicType;
MIL_TEXT_CHAR ImageFilesSource[NUM_IMAGES_TO_REGISTER][260];
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
for (i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
{
MosSprintf(ImageFilesSource[i], 260, IMAGE_FILES_SOURCE, i);
}
MosPrintf(MIL_TEXT("\nREGISTRATION MODULE:\n"));
MosPrintf(MIL_TEXT("---------------------\n\n"));
MosPrintf(MIL_TEXT("This program will make a mosaic from many source images.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
for (i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
MbufRestore(ImageFilesSource[i], MilSystem, &MilSourceImages[i]);
for (i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
{
MdispSelect(MilDisplay, MilSourceImages[i]);
MosPrintf(MIL_TEXT("image %ld.\n"), i);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
}
MgraAllocList(MilSystem, M_DEFAULT, &MilGraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, MilGraphicList);
MregAlloc(MilSystem, M_STITCHING, M_DEFAULT, &MilRegContext);
MregAllocResult(MilSystem, M_DEFAULT, &MilRegResult);
MregControl(MilRegContext, M_CONTEXT, M_TRANSFORMATION_TYPE, M_TRANSLATION);
MregControl(MilRegContext, M_CONTEXT, M_LOCATION_DELTA, 100);
MregCalculate(MilRegContext, MilSourceImages, MilRegResult,
NUM_IMAGES_TO_REGISTER, M_DEFAULT);
MregGetResult(MilRegResult, M_GENERAL, M_RESULT + M_TYPE_MIL_INT, &Result);
if( Result == M_SUCCESS )
{
MregGetResult(MilRegResult, M_GENERAL, M_MOSAIC_SIZE_X + M_TYPE_MIL_INT,
&MosaicSizeX);
MregGetResult(MilRegResult, M_GENERAL, M_MOSAIC_SIZE_Y + M_TYPE_MIL_INT,
&MosaicSizeY);
MbufInquire(MilSourceImages[0], M_SIZE_BAND, &MosaicSizeBand);
MbufInquire(MilSourceImages[0], M_TYPE , &MosaicType );
MbufAllocColor(MilSystem, MosaicSizeBand, MosaicSizeX, MosaicSizeY, MosaicType,
M_IMAGE+M_PROC+M_DISP, &MilMosaicImage);
MregTransformImage(MilRegResult, MilSourceImages, MilMosaicImage,
NUM_IMAGES_TO_REGISTER, M_BILINEAR+M_OVERSCAN_CLEAR, M_DEFAULT);
MdispSelect(MilDisplay, MilMosaicImage);
MgraColor(M_DEFAULT, M_RGB888(0, 0xFF, 0));
MosPrintf(MIL_TEXT("mosaic image.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MregDraw(M_DEFAULT, MilRegResult, MilGraphicList, M_DRAW_BOX, M_ALL, M_DEFAULT);
for (i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
{
MIL_DOUBLE SourcePosX,
SourcePosY,
MosaicPosX,
MosaicPosY;
MIL_INT MosaicPosXMilInt,
MosaicPosYMilInt;
SourcePosX = 0.5 * (MIL_DOUBLE)MbufInquire(MilSourceImages[i], M_SIZE_X, NULL);
SourcePosY = 0.5 * (MIL_DOUBLE)MbufInquire(MilSourceImages[i], M_SIZE_Y, NULL);
MregTransformCoordinate(MilRegResult, i, M_MOSAIC, SourcePosX, SourcePosY,
&MosaicPosX, &MosaicPosY, M_DEFAULT);
MosaicPosXMilInt = (MIL_INT)(MosaicPosX + 0.5);
MosaicPosYMilInt = (MIL_INT)(MosaicPosY + 0.5);
MgraLine(M_DEFAULT, MilGraphicList, MosaicPosXMilInt - 4, MosaicPosYMilInt ,
MosaicPosXMilInt + 4, MosaicPosYMilInt );
MgraLine(M_DEFAULT, MilGraphicList, MosaicPosXMilInt , MosaicPosYMilInt - 4,
MosaicPosXMilInt , MosaicPosYMilInt + 4);
}
MosPrintf(MIL_TEXT("The bounding boxes and the center of all source images\n"));
MosPrintf(MIL_TEXT("have been drawn in the mosaic.\n"));
}
else
{
MosPrintf(MIL_TEXT("Error: Registration was not successful.\n"));
}
MosPrintf(MIL_TEXT("\nPress <Enter> to end.\n\n"));
MosGetch();
MgraFree(MilGraphicList);
if (MilMosaicImage != M_NULL)
MbufFree(MilMosaicImage);
MregFree(MilRegContext);
MregFree(MilRegResult);
for (i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
MbufFree(MilSourceImages[i]);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}