#include <mil.h>
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("HistogramEqualizeAdaptive\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("This program demonstrates how to use MimHistogramEqualizeAdaptive\n")
MIL_TEXT(" to enhance a source image using a contrast limited adaptive\n")
MIL_TEXT(" histogram equalization operation.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Modules used: application, system, display, buffer,\n")
MIL_TEXT("graphic, image processing.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
}
void Annotate(MIL_ID MilGraContext, MIL_ID MilOverlayImage);
#define EXAMPLE_IMAGE_PATH M_IMAGE_PATH MIL_TEXT("HistogramEqualizeAdaptive/")
static MIL_CONST_TEXT_PTR IMAGE_FILE = EXAMPLE_IMAGE_PATH MIL_TEXT("ArmsMono8bit.mim");
int MosMain(void)
{
PrintHeader();
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilOverlayImage,
MilSourceImage,
MilDisplayImage,
MilDispChildImage0,
MilDispChildImage1,
MilHistogramEqualizeAdaptiveContext,
MilGraContext;
MIL_INT ImageSizeBand,
ImageWidth,
ImageHeight,
ImageType;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MgraAlloc(MilSystem, &MilGraContext);
MbufRestore(IMAGE_FILE, MilSystem, &MilSourceImage);
MbufInquire(MilSourceImage, M_SIZE_BAND, &ImageSizeBand);
MbufInquire(MilSourceImage, M_SIZE_X , &ImageWidth);
MbufInquire(MilSourceImage, M_SIZE_Y , &ImageHeight);
MbufInquire(MilSourceImage, M_TYPE , &ImageType);
MbufAllocColor(MilSystem,
ImageSizeBand,
ImageWidth * 2,
ImageHeight,
ImageType,
M_IMAGE+M_PROC+M_DISP,
&MilDisplayImage);
MbufClear(MilDisplayImage, 0);
MbufChild2d(MilDisplayImage, 0, 0, ImageWidth, ImageHeight, &MilDispChildImage0);
MbufChild2d(MilDisplayImage, ImageWidth, 0, ImageWidth, ImageHeight, &MilDispChildImage1);
MbufCopy(MilSourceImage, MilDispChildImage0);
MdispSelect(MilDisplay, MilDisplayImage);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MimAlloc(MilSystem, M_HISTOGRAM_EQUALIZE_ADAPTIVE_CONTEXT, M_DEFAULT, &MilHistogramEqualizeAdaptiveContext);
MimHistogramEqualizeAdaptive(MilHistogramEqualizeAdaptiveContext, MilSourceImage, MilDispChildImage1, M_DEFAULT);
Annotate(MilGraContext, MilOverlayImage);
MosPrintf(MIL_TEXT("Press <Enter> to terminate.\n\n"));
MosGetch();
MbufFree(MilSourceImage);
MbufFree(MilDispChildImage0);
MbufFree(MilDispChildImage1);
MbufFree(MilDisplayImage);
MgraFree(MilGraContext);
MdispFree(MilDisplay);
MimFree(MilHistogramEqualizeAdaptiveContext);
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
return 0;
}
void Annotate(MIL_ID MilGraContext, MIL_ID MilOverlayImage)
{
MIL_INT OverlaySizeX;
MIL_INT OverlaySizeY;
MbufInquire(MilOverlayImage, M_SIZE_X, &OverlaySizeX);
MbufInquire(MilOverlayImage, M_SIZE_Y, &OverlaySizeY);
MgraColor(MilGraContext, M_COLOR_GREEN);
MgraText(MilGraContext, MilOverlayImage, OverlaySizeX / 4 - 48, OverlaySizeY - 24, MIL_TEXT("Source image"));
MgraText(MilGraContext, MilOverlayImage, OverlaySizeX * 3 / 4 - 64, OverlaySizeY - 24, MIL_TEXT("Destination image"));
}