using System;
using System.Collections.Generic;
using System.Text;
using Matrox.MatroxImagingLibrary;
namespace MImHistogram
{
class Program
{
private const string IMAGE_FILE = MIL.M_IMAGE_PATH + "Cell.mim";
private const int HIST_NUM_INTENSITIES = 256;
private const int HIST_SCALE_FACTOR = 8;
private const int HIST_X_POSITION = 250;
private const int HIST_Y_POSITION = 450;
static void Main(string[] args)
{
MIL_ID MilApplication = MIL.M_NULL;
MIL_ID MilSystem = MIL.M_NULL;
MIL_ID MilDisplay = MIL.M_NULL;
MIL_ID MilImage = MIL.M_NULL;
MIL_ID MilOverlayImage = MIL.M_NULL;
MIL_ID HistResult = MIL.M_NULL;
MIL_INT[] HistValues = new MIL_INT[HIST_NUM_INTENSITIES];
double[] XStart = new double[HIST_NUM_INTENSITIES];
double[] YStart = new double[HIST_NUM_INTENSITIES];
double[] XEnd = new double[HIST_NUM_INTENSITIES];
double[] YEnd = new double[HIST_NUM_INTENSITIES];
double AnnotationColor = MIL.M_COLOR_RED;
MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);
MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage);
MIL.MdispSelect(MilDisplay, MilImage);
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE);
MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, ref MilOverlayImage);
MIL.MimAllocResult(MilSystem, HIST_NUM_INTENSITIES, MIL.M_HIST_LIST, ref HistResult);
MIL.MimHistogram(MilImage, HistResult);
MIL.MimGetResult(HistResult, MIL.M_VALUE, HistValues);
MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor);
for (int 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);
}
MIL.MgraLines(MIL.M_DEFAULT, MilOverlayImage, HIST_NUM_INTENSITIES, XStart, YStart, XEnd, YEnd, MIL.M_DEFAULT);
Console.Write("\nHISTOGRAM:\n");
Console.Write("----------\n\n");
Console.Write("The histogram of the image was calculated and drawn.\n");
Console.Write("Press <Enter> to end.\n\n");
Console.ReadKey();
MIL.MimFree(HistResult);
MIL.MbufFree(MilImage);
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
}
}
}