#include <mil.h>
#include <math.h>
#define IMAGE_FILE1 M_IMAGE_PATH MIL_TEXT("CircuitsBoard.mim")
#define IMAGE_FILE2 M_IMAGE_PATH MIL_TEXT("Candy.mim")
void CustomMathLut(MIL_ID MilSystem, MIL_ID MilDisplay);
void PseudoColorMap(MIL_ID MilSystem, MIL_ID MilDisplay);
void HueColorMap(MIL_ID MilSystem, MIL_ID MilDisplay);
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("MgenLutFunction\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("This program shows how MgenLutFunction() can generate\n")
MIL_TEXT("various LUT (lookup table) profiles using:\n\n")
MIL_TEXT("\t1 - Custom mathematical functions to change\n")
MIL_TEXT("\t the dynamic of an image.\n\n")
MIL_TEXT("\t2 - A specific color-map to enhance display.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Modules used: application, system, display, buffer,\n")
MIL_TEXT("image processing, data generation.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
}
int MosMain(void)
{
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);
PrintHeader();
CustomMathLut(MilSystem, MilDisplay);
PseudoColorMap(MilSystem, MilDisplay);
HueColorMap(MilSystem, MilDisplay);
MdispFree(MilDisplay);
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
return 0;
}
void CustomMathLut(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilDispImage,
MilLeftSubImage,
MilRightSubImage,
MilMonoLut;
MIL_DOUBLE a, b, c;
MIL_INT SizeX,
SizeY;
const MIL_INT ImageMinValue = 0;
const MIL_INT ImageMaxValue = 255;
MosPrintf(MIL_TEXT("1 -Image dynamic modification using a custom LUT.\n")
MIL_TEXT("-------------------------------------------------\n\n"));
MbufDiskInquire(IMAGE_FILE1, M_SIZE_X, &SizeX);
MbufDiskInquire(IMAGE_FILE1, M_SIZE_Y, &SizeY);
MbufAlloc2d(MilSystem, SizeX * 2, SizeY , 8 + M_UNSIGNED, M_IMAGE + M_DISP + M_PROC, &MilDispImage);
MbufClear(MilDispImage, 0L);
MdispSelect(MilDisplay, MilDispImage);
MbufChild2d(MilDispImage, 0L, 0L, SizeX, SizeY, &MilLeftSubImage);
MbufChild2d(MilDispImage, SizeX, 0L, SizeX, SizeY, &MilRightSubImage);
MbufLoad(IMAGE_FILE1, MilLeftSubImage);
MosPrintf(MIL_TEXT("An 8-bit monochrome image is loaded and displayed.\n\n"));
MbufAlloc1d(MilSystem, 256, 8 + M_UNSIGNED, M_LUT, &MilMonoLut);
a = ImageMaxValue/log10((MIL_DOUBLE)ImageMaxValue), b = 10, c =0;;
MgenLutFunction(MilMonoLut, M_LOG, a, b, c, ImageMinValue, (MIL_DOUBLE)ImageMinValue, ImageMaxValue);
MimLutMap(MilLeftSubImage, MilRightSubImage, MilMonoLut);
MosPrintf(MIL_TEXT("The source image intensities were transformed with\n"));
MosPrintf(MIL_TEXT("a LUT that was filled using a M_LOG function.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
a = 1.0 / (MIL_DOUBLE)ImageMaxValue, b = 2, c = 0;
MgenLutFunction(MilMonoLut, M_POWER, a, b, c, ImageMinValue, (MIL_DOUBLE)ImageMinValue, ImageMaxValue);
MimLutMap(MilLeftSubImage, MilRightSubImage, MilMonoLut);
MosPrintf(MIL_TEXT("The source image intensities were transformed with\n"));
MosPrintf(MIL_TEXT("a LUT that was filled using a M_POWER function.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MIL_DOUBLE InflectionValue = (ImageMinValue + ImageMaxValue) / 2;
MgenLutRamp(MilMonoLut, ImageMinValue, (MIL_DOUBLE)ImageMinValue, (MIL_INT)InflectionValue, (MIL_DOUBLE)ImageMaxValue);
MgenLutRamp(MilMonoLut, (MIL_INT)InflectionValue, (MIL_DOUBLE)ImageMaxValue, ImageMaxValue, (MIL_DOUBLE)ImageMinValue);
MimLutMap(MilLeftSubImage, MilRightSubImage, MilMonoLut);
MosPrintf(MIL_TEXT("The source image intensities were transformed with\n"));
MosPrintf(MIL_TEXT("a LUT that was filled using a piecewise linear function.\n\n"));
MosGetch();
MbufFree(MilMonoLut);
MbufFree(MilRightSubImage);
MbufFree(MilLeftSubImage);
MbufFree(MilDispImage);
}
void PseudoColorMap(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilDispImage,
MilMonoImage,
MilLeftSubImage,
MilRightSubImage,
MilLut;
MIL_INT SizeX,
SizeY;
MosPrintf(MIL_TEXT("2 -Pseudo-color display using a color-map LUT.\n")
MIL_TEXT("----------------------------------------------\n\n"));
MbufRestore(IMAGE_FILE1, MilSystem, &MilMonoImage);
MbufInquire(MilMonoImage, M_SIZE_X, &SizeX);
MbufInquire(MilMonoImage, M_SIZE_Y, &SizeY);
MbufAllocColor(MilSystem, 3, SizeX * 2, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_DISP + M_PROC, &MilDispImage);
MbufClear(MilDispImage, 0L);
MdispSelect(MilDisplay, MilDispImage);
MbufChildColor2d(MilDispImage, M_ALL_BANDS, 0L, 0L, SizeX, SizeY, &MilLeftSubImage);
MbufChildColor2d(MilDispImage, M_ALL_BANDS, SizeX, 0L, SizeX, SizeY, &MilRightSubImage);
MbufCopy(MilMonoImage, MilLeftSubImage);
MosPrintf(MIL_TEXT("An 8-bit monochrome image is loaded and displayed.\n\n"));
MbufAllocColor(MilSystem, 3, 256, 1, 8 + M_UNSIGNED, M_LUT, &MilLut);
MgenLutFunction(MilLut, M_COLORMAP_HOT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT);
MimLutMap(MilMonoImage, MilRightSubImage, MilLut);
MosPrintf(MIL_TEXT("The image is displayed using a M_COLORMAP_HOT LUT.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgenLutFunction(MilLut, M_COLORMAP_JET, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT);
MimLutMap(MilMonoImage, MilRightSubImage, MilLut);
MosPrintf(MIL_TEXT("The image is displayed using a M_COLORMAP_JET LUT.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgenLutFunction(MilLut, M_COLORMAP_SPECTRUM, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT);
MimLutMap(MilMonoImage, MilRightSubImage, MilLut);
MosPrintf(MIL_TEXT("The image is displayed using a M_COLORMAP_SPECTRUM LUT.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgenLutFunction(MilLut, M_COLORMAP_TURBO, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT);
MimLutMap(MilMonoImage, MilRightSubImage, MilLut);
MosPrintf(MIL_TEXT("The image is displayed using a M_COLORMAP_TURBO LUT.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilLut);
MbufFree(MilRightSubImage);
MbufFree(MilLeftSubImage);
MbufFree(MilMonoImage);
MbufFree(MilDispImage);
}
void HueColorMap(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilDispImage,
MilMonoImage,
MilLeftSubImage,
MilRightSubImage,
MilLut;
MIL_INT SizeX,
SizeY;
MosPrintf(MIL_TEXT("3 -Hue component display using a M_COLORMAP_HUE LUT.\n")
MIL_TEXT("---------------------------------------------------\n\n"));
MbufDiskInquire(IMAGE_FILE2, M_SIZE_X, &SizeX);
MbufDiskInquire(IMAGE_FILE2, M_SIZE_Y, &SizeY);
MbufAllocColor(MilSystem, 3, SizeX * 2, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_DISP + M_PROC, &MilDispImage);
MbufClear(MilDispImage, 0L);
MdispSelect(MilDisplay, MilDispImage);
MbufChildColor2d(MilDispImage, M_ALL_BANDS, 0L, 0L, SizeX, SizeY, &MilLeftSubImage);
MbufChildColor2d(MilDispImage, M_ALL_BANDS, SizeX, 0L, SizeX, SizeY, &MilRightSubImage);
MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilMonoImage);
MbufLoad(IMAGE_FILE2, MilLeftSubImage);
MosPrintf(MIL_TEXT("A color image is loaded and displayed.\n\n"));
MimConvert(MilLeftSubImage, MilMonoImage, M_RGB_TO_H);
MbufAllocColor(MilSystem, 3, 256, 1, 8 + M_UNSIGNED, M_LUT, &MilLut);
MgenLutFunction(MilLut, M_COLORMAP_HUE, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT);
MimLutMap(MilMonoImage, MilRightSubImage, MilLut);
MosPrintf(MIL_TEXT("The hue component of the image is displayed\n"));
MosPrintf(MIL_TEXT("using a hue color-map LUT.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
MbufFree(MilMonoImage);
MbufFree(MilLut);
MbufFree(MilRightSubImage);
MbufFree(MilLeftSubImage);
MbufFree(MilDispImage);
}