using System;
using System.Collections.Generic;
using System.Text;
using Matrox.MatroxImagingLibrary;
namespace MImProcessing
{
class Program
{
private const string IMAGE_FILE = MIL.M_IMAGE_PATH + "Cell.mim";
private const int IMAGE_SMALL_PARTICLE_RADIUS = 1;
static void Main(string[] args)
{
MIL_ID MilApplication = MIL.M_NULL;
MIL_ID MilRemoteApplication = MIL.M_NULL;
MIL_ID MilSystem = MIL.M_NULL;
MIL_ID MilDisplay = MIL.M_NULL;
MIL_ID MilImage = MIL.M_NULL;
MIL_ID MilExtremeResult = 0;
MIL_INT MaxLabelNumber = 0;
MIL_INT LicenseModules = 0;
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);
Console.Write("\nIMAGE PROCESSING:\n");
Console.Write("-----------------\n\n");
Console.Write("This program extracts the dark particles in the image.\n");
Console.Write("Press <Enter> to continue.\n\n");
Console.ReadKey();
MIL.MimBinarize(MilImage, MilImage, MIL.M_BIMODAL + MIL.M_LESS_OR_EQUAL, MIL.M_NULL, MIL.M_NULL);
Console.Write("These particles were extracted from the original image.\n");
MIL.MsysInquire(MilSystem, MIL.M_OWNER_APPLICATION, ref MilRemoteApplication);
MIL.MappInquire(MilRemoteApplication, MIL.M_LICENSE_MODULES, ref LicenseModules);
if ((LicenseModules & MIL.M_LICENSE_IM) != 0)
{
Console.Write("Press <Enter> to continue.\n\n");
Console.ReadKey();
MIL.MimClose(MilImage, MilImage, IMAGE_SMALL_PARTICLE_RADIUS, MIL.M_BINARY);
MIL.MimOpen(MilImage, MilImage, IMAGE_SMALL_PARTICLE_RADIUS, MIL.M_BINARY);
MIL.MimLabel(MilImage, MilImage, MIL.M_DEFAULT);
MIL.MimAllocResult(MilSystem, 1, MIL.M_EXTREME_LIST, ref MilExtremeResult);
MIL.MimFindExtreme(MilImage, MilExtremeResult, MIL.M_MAX_VALUE);
MIL.MimGetResult(MilExtremeResult, MIL.M_VALUE, ref MaxLabelNumber);
MIL.MimFree(MilExtremeResult);
MIL.MimArith(MilImage, (int)(256 / (double)MaxLabelNumber), MilImage, MIL.M_MULT_CONST);
MIL.MdispLut(MilDisplay, MIL.M_PSEUDO);
Console.Write("There were {0} large particles in the original image.\n", MaxLabelNumber);
}
Console.Write("Press <Enter> to end.\n\n");
Console.ReadKey();
MIL.MbufFree(MilImage);
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
}
}
}