#include <mil.h>
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Cell.mim")
#define HIST_NUM_INTENSITIES 256
#define HIST_SCALE_FACTOR 8
#define HIST_X_POSITION 250
#define HIST_Y_POSITION 450
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilImage,
MilOverlayImage,
HistResult;
MIL_INT HistValues[HIST_NUM_INTENSITIES];
MIL_INT XStart[HIST_NUM_INTENSITIES], YStart[HIST_NUM_INTENSITIES],
XEnd[HIST_NUM_INTENSITIES], YEnd[HIST_NUM_INTENSITIES];
MIL_DOUBLE AnnotationColor = M_COLOR_RED;
MIL_INT i;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MimAllocResult(MilSystem, HIST_NUM_INTENSITIES, M_HIST_LIST, &HistResult);
MimHistogram(MilImage, HistResult);
MimGetResult(HistResult, M_VALUE, HistValues);
MgraColor(M_DEFAULT, AnnotationColor);
for(i=0; i<HIST_NUM_INTENSITIES; i++)
{
XStart[i] = i+HIST_X_POSITION+1,
YStart[i] = HIST_Y_POSITION;
XEnd[i] = i+HIST_X_POSITION+1,
YEnd[i] = HIST_Y_POSITION-(HistValues[i]/HIST_SCALE_FACTOR);
}
MgraLines(M_DEFAULT, MilOverlayImage, HIST_NUM_INTENSITIES,
XStart, YStart, XEnd, YEnd, M_DEFAULT);
MosPrintf(MIL_TEXT("\nHISTOGRAM:\n"));
MosPrintf(MIL_TEXT("----------\n\n"));
MosPrintf(MIL_TEXT("The histogram of the image was calculated and drawn.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
MimFree(HistResult);
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}