'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MImHistogram
Friend Class Program
Private Const IMAGE_FILE As String = MIL.M_IMAGE_PATH & "Cell.mim"
Private Const HIST_NUM_INTENSITIES As Integer = 256
Private Const HIST_SCALE_FACTOR As Integer = 8
Private Const HIST_X_POSITION As Integer = 250
Private Const HIST_Y_POSITION As Integer = 450
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImage As MIL_ID = MIL.M_NULL
Dim MilOverlayImage As MIL_ID = MIL.M_NULL
Dim HistResult As MIL_ID = MIL.M_NULL
Dim HistValues(HIST_NUM_INTENSITIES - 1) As MIL_INT
Dim XStart(HIST_NUM_INTENSITIES - 1) As Double
Dim YStart(HIST_NUM_INTENSITIES - 1) As Double
Dim XEnd(HIST_NUM_INTENSITIES - 1) As Double
Dim YEnd(HIST_NUM_INTENSITIES - 1) As Double
Dim AnnotationColor As Double = MIL.M_COLOR_RED
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilImage)
MIL.MdispSelect(MilDisplay, MilImage)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE)
MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, MilOverlayImage)
MIL.MimAllocResult(MilSystem, HIST_NUM_INTENSITIES, MIL.M_HIST_LIST, HistResult)
MIL.MimHistogram(MilImage, HistResult)
MIL.MimGetResult(HistResult, MIL.M_VALUE, HistValues)
MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor)
For i As Integer = 0 To HIST_NUM_INTENSITIES - 1
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)
Next i
MIL.MgraLines(MIL.M_DEFAULT, MilOverlayImage, HIST_NUM_INTENSITIES, XStart, YStart, XEnd, YEnd, MIL.M_DEFAULT)
Console.Write(Constants.vbLf + "HISTOGRAM:" + Constants.vbLf)
Console.Write("----------" + Constants.vbLf + Constants.vbLf)
Console.Write("The histogram of the image was calculated and drawn." + Constants.vbLf)
Console.Write("Press <Enter> to end." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MimFree(HistResult)
MIL.MbufFree(MilImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Class
End Namespace