'
'
'
'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MCol
Friend Class Program
Private Const DISPLAY_CENTER_MARGIN_X As Integer = 5
Private Const COLOR_PATCH_SIZEX As Integer = 30
Private Const COLOR_PATCH_SIZEY As Integer = 40
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
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
ColorSegmentationExample(MilSystem, MilDisplay)
ColorMatchingExample(MilSystem, MilDisplay)
ColorSeparationExample(MilSystem, MilDisplay)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
Private Const CANDY_SAMPLE_IMAGE_FILE As String = MIL.M_IMAGE_PATH & "CandySamples.mim"
Private Const CANDY_TARGET_IMAGE_FILE As String = MIL.M_IMAGE_PATH & "Candy.mim"
Private Const NUM_SAMPLES As Integer = 6
Private Const CANDY_SAMPLES_XSPACING As Integer = 35
Private Const CANDY_SAMPLES_YOFFSET As Integer = 145
Private Const MATCH_MODE As Integer = MIL.M_MIN_DIST_VOTE
Private Const DISTANCE_TYPE As Integer = MIL.M_MAHALANOBIS
Private Const TOLERANCE_MODE As Integer = MIL.M_SAMPLE_STDDEV
Private Const TOLERANCE_VALUE As Double = 6.0
Private Const RED_TOLERANCE_VALUE As Double = 6.0
Private Const YELLOW_TOLERANCE_VALUE As Double = 12.0
Private Const PINK_TOLERANCE_VALUE As Double = 5.0
Private Shared Sub ColorSegmentationExample(ByVal MilSystem As MIL_ID, ByVal MilDisplay As MIL_ID)
Dim SourceChild As MIL_ID = MIL.M_NULL
Dim DestChild As MIL_ID = MIL.M_NULL
Dim MatchContext As MIL_ID = MIL.M_NULL
Dim MatchResult As MIL_ID = MIL.M_NULL
Dim DisplayImage As MIL_ID = MIL.M_NULL
Dim SourceSizeX As MIL_INT = 0
Dim SourceSizeY As MIL_INT = 0
Dim SampleIndex As MIL_INT = 0
Dim SpacesIndex As MIL_INT = 0
Dim MatchScore As Double = 0.0
Dim Spaces() As String = {"", " ", " ", " "}
Dim SampleNames() As String = {"Green", "Red", "Yellow", "Purple", "Blue", "Pink"}
Dim SamplesROI(,) As Double = {{58, 143}, {136, 148}, {217, 144}, {295, 142}, {367, 143}, {442, 147}}
Const SampleSizeX As Double = 36, SampleSizeY As Double = 32
Dim SampleMatchColor(NUM_SAMPLES - 1, 2) As MIL_INT
Console.Write(Constants.vbLf + "COLOR SEGMENTATION:" + Constants.vbLf)
Console.Write("-------------------" + Constants.vbLf)
MIL.MbufDiskInquire(CANDY_SAMPLE_IMAGE_FILE, MIL.M_SIZE_X, SourceSizeX)
MIL.MbufDiskInquire(CANDY_SAMPLE_IMAGE_FILE, MIL.M_SIZE_Y, SourceSizeY)
MIL.MbufAllocColor(MilSystem, 3, 2 * SourceSizeX + DISPLAY_CENTER_MARGIN_X, SourceSizeY, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_DISP + MIL.M_PROC, DisplayImage)
MIL.MbufClear(DisplayImage, MIL.M_COLOR_BLACK)
MIL.MbufChild2d(DisplayImage, 0, 0, SourceSizeX, SourceSizeY, SourceChild)
MIL.MbufChild2d(DisplayImage, SourceSizeX + DISPLAY_CENTER_MARGIN_X, 0, SourceSizeX, SourceSizeY, DestChild)
MIL.MbufLoad(CANDY_SAMPLE_IMAGE_FILE, SourceChild)
MIL.McolAlloc(MilSystem, MIL.M_COLOR_MATCHING, MIL.M_RGB, MIL.M_DEFAULT, MIL.M_DEFAULT, MatchContext)
For i As Integer = 0 To NUM_SAMPLES - 1
MIL.McolDefine(MatchContext, SourceChild, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_IMAGE, SamplesROI(i, 0), SamplesROI(i, 1), SampleSizeX, SampleSizeY)
Next i
MIL.McolSetMethod(MatchContext, MATCH_MODE, DISTANCE_TYPE, MIL.M_DEFAULT, MIL.M_DEFAULT)
MIL.McolControl(MatchContext, MIL.M_CONTEXT, MIL.M_DISTANCE_TOLERANCE_MODE, TOLERANCE_MODE)
MIL.McolControl(MatchContext, MIL.M_ALL, MIL.M_DISTANCE_TOLERANCE, TOLERANCE_VALUE)
MIL.McolControl(MatchContext, MIL.M_SAMPLE_INDEX(1), MIL.M_DISTANCE_TOLERANCE, RED_TOLERANCE_VALUE)
MIL.McolControl(MatchContext, MIL.M_SAMPLE_INDEX(2), MIL.M_DISTANCE_TOLERANCE, YELLOW_TOLERANCE_VALUE)
MIL.McolControl(MatchContext, MIL.M_SAMPLE_INDEX(5), MIL.M_DISTANCE_TOLERANCE, PINK_TOLERANCE_VALUE)
MIL.McolPreprocess(MatchContext, MIL.M_DEFAULT)
For i As Integer = 0 To NUM_SAMPLES - 1
MIL.McolInquire(MatchContext, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_MATCH_SAMPLE_COLOR_BAND_0 + MIL.M_TYPE_MIL_INT, SampleMatchColor(i, 0))
MIL.McolInquire(MatchContext, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_MATCH_SAMPLE_COLOR_BAND_1 + MIL.M_TYPE_MIL_INT, SampleMatchColor(i, 1))
MIL.McolInquire(MatchContext, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_MATCH_SAMPLE_COLOR_BAND_2 + MIL.M_TYPE_MIL_INT, SampleMatchColor(i, 2))
Next i
DrawSampleColors(DestChild, SampleMatchColor, SampleNames, NUM_SAMPLES, CANDY_SAMPLES_XSPACING, CANDY_SAMPLES_YOFFSET)
MIL.MdispSelect(MilDisplay, DisplayImage)
Console.Write("Color samples are defined for each possible candy color." + Constants.vbLf)
Console.Write("Press <Enter> to do color matching." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MbufClear(DisplayImage, MIL.M_COLOR_BLACK)
MIL.MbufLoad(CANDY_TARGET_IMAGE_FILE, SourceChild)
MIL.McolAllocResult(MilSystem, MIL.M_COLOR_MATCHING_RESULT, MIL.M_DEFAULT, MatchResult)
MIL.McolControl(MatchContext, MIL.M_CONTEXT, MIL.M_GENERATE_PIXEL_MATCH, MIL.M_ENABLE)
MIL.McolControl(MatchContext, MIL.M_CONTEXT, MIL.M_GENERATE_SAMPLE_COLOR_LUT, MIL.M_ENABLE)
MIL.McolMatch(MatchContext, SourceChild, MIL.M_DEFAULT, MIL.M_NULL, MatchResult, MIL.M_DEFAULT)
Console.Write("Each pixel of the mixture is matched " & "with one of the color samples." + Constants.vbLf)
Console.Write(Constants.vbLf + "Color segmentation results:" + Constants.vbLf)
Console.Write("---------------------------" + Constants.vbLf)
For SampleIndex = 0 To NUM_SAMPLES - 1
MIL.McolGetResult(MatchResult, MIL.M_DEFAULT, MIL.M_SAMPLE_INDEX(CType(SampleIndex, Integer)), MIL.M_SCORE, MatchScore)
SpacesIndex = 6 - SampleNames(CType(SampleIndex, Integer)).Length
Console.Write("Ratio of {0}{1} sample = {2,5:0.00}%" + Constants.vbLf, SampleNames(CType(SampleIndex, Integer)), Spaces(CType(SpacesIndex, Integer)), MatchScore)
Next SampleIndex
Console.Write(Constants.vbLf + "Results reveal the low proportion of Blue candy." + Constants.vbLf)
MIL.McolDraw(MIL.M_DEFAULT, MatchResult, DestChild, MIL.M_DRAW_PIXEL_MATCH_USING_COLOR, MIL.M_ALL, MIL.M_ALL, MIL.M_DEFAULT)
Console.Write(Constants.vbLf + "Press <Enter> to end." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MbufFree(DestChild)
MIL.MbufFree(SourceChild)
MIL.MbufFree(DisplayImage)
MIL.McolFree(MatchResult)
MIL.McolFree(MatchContext)
End Sub
Private Const FUSE_SAMPLES_IMAGE As String = MIL.M_IMAGE_PATH & "FuseSamples.mim"
Private Const FUSE_TARGET_IMAGE As String = MIL.M_IMAGE_PATH & "Fuse.mim"
Private Const FINDER_CONTEXT As String = MIL.M_IMAGE_PATH & "FuseModel.mmf"
Private Const NUM_FUSES As Integer = 4
Private Const FUSE_SAMPLES_XSPACING As Integer = 40
Private Const FUSE_SAMPLES_YOFFSET As Integer = 145
Private Shared Sub ColorMatchingExample(ByVal MilSystem As MIL_ID, ByVal MilDisplay As MIL_ID)
Dim DisplayImage As MIL_ID = MIL.M_NULL
Dim SourceChild As MIL_ID = MIL.M_NULL
Dim DestChild As MIL_ID = MIL.M_NULL
Dim ColMatchContext As MIL_ID = MIL.M_NULL
Dim ColMatchResult As MIL_ID = MIL.M_NULL
Dim ModelImage As MIL_ID = MIL.M_NULL
Dim AreaImage As MIL_ID = MIL.M_NULL
Dim OverlayID As MIL_ID = MIL.M_NULL
Dim OverlaySourceChild As MIL_ID = MIL.M_NULL
Dim OverlayDestChild As MIL_ID = MIL.M_NULL
Dim FuseFinderCtx As MIL_ID = MIL.M_NULL
Dim FuseFinderRes As MIL_ID = MIL.M_NULL
Dim SizeX As MIL_INT = 0
Dim SizeY As MIL_INT = 0
Dim SampleNames() As String = {"Green", " Blue", " Red", "Yellow"}
Dim SampleROIs(,) As MIL_INT = {{54, 139, 28, 14}, {172, 137, 30, 23}, {296, 135, 31, 23}, {417, 134, 27, 22}}
Dim SampleMatchColor(NUM_FUSES - 1, 2) As MIL_INT
Console.Write(Constants.vbLf + "COLOR IDENTIFICATION:" + Constants.vbLf)
Console.Write("---------------------" + Constants.vbLf)
MIL.MbufDiskInquire(FUSE_TARGET_IMAGE, MIL.M_SIZE_X, SizeX)
MIL.MbufDiskInquire(FUSE_TARGET_IMAGE, MIL.M_SIZE_Y, SizeY)
MIL.MbufAllocColor(MilSystem, 3, 2 * SizeX + DISPLAY_CENTER_MARGIN_X, SizeY, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_DISP + MIL.M_PROC, DisplayImage)
MIL.MbufClear(DisplayImage, MIL.M_COLOR_BLACK)
MIL.MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ModelImage)
MIL.MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, AreaImage)
MIL.MbufChild2d(DisplayImage, 0, 0, SizeX, SizeY, SourceChild)
MIL.MbufChild2d(DisplayImage, SizeX + DISPLAY_CENTER_MARGIN_X, 0, SizeX, SizeY, DestChild)
MIL.MbufLoad(FUSE_SAMPLES_IMAGE, SourceChild)
MIL.MdispSelect(MilDisplay, DisplayImage)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT)
MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, OverlayID)
MIL.MbufChild2d(OverlayID, 0, 0, SizeX, SizeY, OverlaySourceChild)
MIL.MbufChild2d(OverlayID, SizeX + DISPLAY_CENTER_MARGIN_X, 0, SizeX, SizeY, OverlayDestChild)
MIL.MmodRestore(FINDER_CONTEXT, MilSystem, MIL.M_DEFAULT, FuseFinderCtx)
MIL.MmodPreprocess(FuseFinderCtx, MIL.M_DEFAULT)
MIL.MmodAllocResult(MilSystem, MIL.M_DEFAULT, FuseFinderRes)
MIL.McolAlloc(MilSystem, MIL.M_COLOR_MATCHING, MIL.M_RGB, MIL.M_DEFAULT, MIL.M_DEFAULT, ColMatchContext)
MIL.McolAllocResult(MilSystem, MIL.M_COLOR_MATCHING_RESULT, MIL.M_DEFAULT, ColMatchResult)
For i As Integer = 0 To NUM_FUSES - 1
MIL.McolDefine(ColMatchContext, SourceChild, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_IMAGE, CDbl(SampleROIs(i, 0)), CDbl(SampleROIs(i, 1)), CDbl(SampleROIs(i, 2)), CDbl(SampleROIs(i, 3)))
Next i
MIL.McolPreprocess(ColMatchContext, MIL.M_DEFAULT)
For i As Integer = 0 To NUM_FUSES - 1
MIL.McolInquire(ColMatchContext, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_MATCH_SAMPLE_COLOR_BAND_0 + MIL.M_TYPE_MIL_INT, SampleMatchColor(i, 0))
MIL.McolInquire(ColMatchContext, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_MATCH_SAMPLE_COLOR_BAND_1 + MIL.M_TYPE_MIL_INT, SampleMatchColor(i, 1))
MIL.McolInquire(ColMatchContext, MIL.M_SAMPLE_LABEL(i + 1), MIL.M_MATCH_SAMPLE_COLOR_BAND_2 + MIL.M_TYPE_MIL_INT, SampleMatchColor(i, 2))
Next i
DrawSampleColors(DestChild, SampleMatchColor, SampleNames, NUM_FUSES, FUSE_SAMPLES_XSPACING, FUSE_SAMPLES_YOFFSET)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_RED)
For SampleIndex As Integer = 0 To NUM_FUSES - 1
Dim XEnd As MIL_INT = SampleROIs(SampleIndex, 0) + SampleROIs(SampleIndex, 2) - 1
Dim YEnd As MIL_INT = SampleROIs(SampleIndex, 1) + SampleROIs(SampleIndex, 3) - 1
MIL.MgraRect(MIL.M_DEFAULT, OverlaySourceChild, SampleROIs(SampleIndex, 0), SampleROIs(SampleIndex, 1), XEnd, YEnd)
Next SampleIndex
Console.Write("Colors are defined using one color sample region per fuse." + Constants.vbLf)
Console.Write("Press <Enter> to process the target image." + Constants.vbLf)
Console.ReadKey()
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT)
MIL.MdispControl(MilDisplay, MIL.M_UPDATE, MIL.M_DISABLE)
MIL.MbufLoad(FUSE_TARGET_IMAGE, SourceChild)
MIL.MimConvert(SourceChild, ModelImage, MIL.M_RGB_TO_L)
MIL.MbufCopy(ModelImage, DestChild)
MIL.MmodFind(FuseFinderCtx, ModelImage, FuseFinderRes)
Dim Number As MIL_INT = 0
MIL.MmodGetResult(FuseFinderRes, MIL.M_DEFAULT, MIL.M_NUMBER + MIL.M_TYPE_MIL_INT, Number)
MIL.MbufClear(AreaImage, 0)
For ii As MIL_INT = 0 To Number - 1
Dim X As Double = 0.0
Dim Y As Double = 0.0
MIL.MmodGetResult(FuseFinderRes, ii, MIL.M_POSITION_X, X)
MIL.MmodGetResult(FuseFinderRes, ii, MIL.M_POSITION_Y, Y)
MIL.MgraColor(MIL.M_DEFAULT, CDbl(ii) + 1)
MIL.MgraArcFill(MIL.M_DEFAULT, AreaImage, X, Y, 20, 20, 0, 360)
Next ii
MIL.McolControl(ColMatchContext, MIL.M_CONTEXT, MIL.M_SAVE_AREA_IMAGE, MIL.M_ENABLE)
MIL.McolControl(ColMatchContext, MIL.M_CONTEXT, MIL.M_GENERATE_SAMPLE_COLOR_LUT, MIL.M_ENABLE)
MIL.McolMatch(ColMatchContext, SourceChild, MIL.M_DEFAULT, AreaImage, ColMatchResult, MIL.M_DEFAULT)
MIL.McolDraw(MIL.M_DEFAULT, ColMatchResult, OverlayDestChild, MIL.M_DRAW_AREA_MATCH_USING_COLOR, MIL.M_ALL, MIL.M_ALL, MIL.M_DEFAULT)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_BLUE)
MIL.MmodDraw(MIL.M_DEFAULT, FuseFinderRes, OverlayDestChild, MIL.M_DRAW_BOX + MIL.M_DRAW_POSITION, MIL.M_ALL, MIL.M_DEFAULT)
MIL.MdispControl(MilDisplay, MIL.M_UPDATE, MIL.M_ENABLE)
Console.Write(Constants.vbLf + "Fuses are located using the Model Finder tool." + Constants.vbLf)
Console.Write("The color of each target area is identified." + Constants.vbLf)
Console.Write("Press <Enter> to end." + Constants.vbLf)
Console.ReadKey()
MIL.MmodFree(FuseFinderRes)
MIL.MmodFree(FuseFinderCtx)
MIL.MbufFree(AreaImage)
MIL.MbufFree(ModelImage)
MIL.MbufFree(SourceChild)
MIL.MbufFree(DestChild)
MIL.MbufFree(OverlaySourceChild)
MIL.MbufFree(OverlayDestChild)
MIL.MbufFree(DisplayImage)
MIL.McolFree(ColMatchContext)
MIL.McolFree(ColMatchResult)
End Sub
Private Const WRITING_IMAGE_FILE As String = MIL.M_IMAGE_PATH & "stamp.mim"
Private Shared ReadOnly BACKGROUND_COLOR() As MIL_INT = {245, 234, 206}
Private Shared ReadOnly WRITING_COLOR() As MIL_INT = {141, 174, 174}
Private Shared ReadOnly STAMP_COLOR() As MIL_INT = {226, 150, 118}
Private Const PATCHES_XSPACING As Integer = 70
Private Shared Sub ColorSeparationExample(ByVal MilSystem As MIL_ID, ByVal MilDisplay As MIL_ID)
Dim DisplayImage As MIL_ID = MIL.M_NULL
Dim SourceChild As MIL_ID = MIL.M_NULL
Dim DestChild As MIL_ID = MIL.M_NULL
Dim Child As MIL_ID = MIL.M_NULL
Dim ColorsArray As MIL_ID = MIL.M_NULL
Dim SourceSizeX As MIL_INT = 0
Dim SourceSizeY As MIL_INT = 0
Dim ColorNames() As String = {"BACKGROUND", "WRITING", "STAMP"}
Dim Colors(,) As MIL_INT = {{245, 234, 206}, {141, 174, 174}, {226, 150, 118}}
Dim BackgroundColor() As Byte = {245, 234, 206}
Dim SelectedColor() As Byte = {141, 174, 174}
Dim RejectedColor() As Byte = {226, 150, 118}
Console.Write(Constants.vbLf + "COLOR SEPARATION:" + Constants.vbLf)
Console.Write("-----------------" + Constants.vbLf)
MIL.MbufAlloc2d(MilSystem, 3, 3, 8 + MIL.M_UNSIGNED, MIL.M_ARRAY, ColorsArray)
MIL.MbufPut2d(ColorsArray, 0, 0, 3, 1, BackgroundColor)
MIL.MbufPut2d(ColorsArray, 0, 1, 3, 1, SelectedColor)
MIL.MbufPut2d(ColorsArray, 0, 2, 3, 1, RejectedColor)
MIL.MbufDiskInquire(WRITING_IMAGE_FILE, MIL.M_SIZE_X, SourceSizeX)
MIL.MbufDiskInquire(WRITING_IMAGE_FILE, MIL.M_SIZE_Y, SourceSizeY)
MIL.MbufAllocColor(MilSystem, 3, 2 * SourceSizeX + DISPLAY_CENTER_MARGIN_X, SourceSizeY, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_DISP + MIL.M_PROC, DisplayImage)
MIL.MbufClear(DisplayImage, MIL.M_COLOR_BLACK)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT)
MIL.MbufChild2d(DisplayImage, 0, 0, SourceSizeX, SourceSizeY, SourceChild)
MIL.MbufChild2d(DisplayImage, SourceSizeX + DISPLAY_CENTER_MARGIN_X, 0, SourceSizeX, SourceSizeY, DestChild)
MIL.MbufLoad(WRITING_IMAGE_FILE, SourceChild)
DrawSampleColors(DestChild, Colors, ColorNames, 3, PATCHES_XSPACING, -1)
MIL.MdispSelect(MilDisplay, DisplayImage)
Console.Write("The writing will be separated from the stamp using the following triplets:" + Constants.vbLf)
Console.Write("the background color: beige [{0}, {1}, {2}]," + Constants.vbLf, BackgroundColor(0), BackgroundColor(1), BackgroundColor(2))
Console.Write("the writing color : green [{0}, {1}, {2}]," + Constants.vbLf, SelectedColor(0), SelectedColor(1), SelectedColor(2))
Console.Write("the stamp color : red [{0}, {1}, {2}]." + Constants.vbLf + Constants.vbLf, RejectedColor(0), RejectedColor(1), RejectedColor(2))
Console.Write("Press <Enter> to extract the writing." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.McolProject(SourceChild, ColorsArray, DestChild, MIL.M_NULL, MIL.M_COLOR_SEPARATION, MIL.M_DEFAULT, CType(MIL.M_NULL, IntPtr))
Console.Write("Press <Enter> to extract the stamp." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MbufPut2d(ColorsArray, 0, 2, 3, 1, SelectedColor)
MIL.MbufPut2d(ColorsArray, 0, 1, 3, 1, RejectedColor)
MIL.McolProject(SourceChild, ColorsArray, DestChild, MIL.M_NULL, MIL.M_COLOR_SEPARATION, MIL.M_DEFAULT, CType(MIL.M_NULL, IntPtr))
Console.Write("Press <Enter> to end." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MbufFree(ColorsArray)
MIL.MbufFree(SourceChild)
MIL.MbufFree(DestChild)
MIL.MbufFree(DisplayImage)
End Sub
Private Shared Sub DrawSampleColors(ByVal DestImage As MIL_ID, ByVal pSamplesColors(,) As MIL_INT, ByVal pSampleNames() As String, ByVal NumSamples As MIL_INT, ByVal XSpacing As MIL_INT, ByVal YOffset As MIL_INT)
Dim DestSizeX As MIL_INT = MIL.MbufInquire(DestImage, MIL.M_SIZE_X, MIL.M_NULL)
Dim DestSizeY As MIL_INT = MIL.MbufInquire(DestImage, MIL.M_SIZE_Y, MIL.M_NULL)
Dim OffsetX As Double = CType((DestSizeX - (NumSamples * COLOR_PATCH_SIZEX) - ((NumSamples - 1) * XSpacing)), Double) / 2.0
Dim OffsetY As Double
If YOffset > 0 Then
OffsetY = YOffset
Else
OffsetY = CType((DestSizeY - COLOR_PATCH_SIZEY), Double) / 2.0
End If
Dim TextOffsetX As Double
MIL.MgraFont(MIL.M_DEFAULT, MIL.M_FONT_DEFAULT_SMALL)
For SampleIndex As Integer = 0 To CType(NumSamples, Integer) - 1
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_RGB888(CType(pSamplesColors(SampleIndex, 0), Integer), CType(pSamplesColors(SampleIndex, 1), Integer), CType(pSamplesColors(SampleIndex, 2), Integer)))
MIL.MgraRectFill(MIL.M_DEFAULT, DestImage, OffsetX, OffsetY, OffsetX + COLOR_PATCH_SIZEX, OffsetY + COLOR_PATCH_SIZEY)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_YELLOW)
TextOffsetX = OffsetX + COLOR_PATCH_SIZEX / 2.0 - 4.0 * pSampleNames(SampleIndex).Length + 0.5
MIL.MgraText(MIL.M_DEFAULT, DestImage, TextOffsetX, OffsetY - 20, pSampleNames(SampleIndex))
OffsetX += CType((COLOR_PATCH_SIZEX + XSpacing), Double)
Next SampleIndex
End Sub
End Class
End Namespace