'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MImSegment
Friend Class Program
Private Const IMAGE_FILE As String = MIL.M_IMAGE_PATH & "pills.mim"
Private Const WATERSHED_MINIMAL_GRADIENT_VARIATION As Integer = 45
Private Const WATERSHED_MINIMAL_DISTANCE_VARIATION As Integer = 2
Private Const PIXEL_FETCH_POSITION_X As Integer = 2
Private Const PIXEL_FETCH_POSITION_Y As Integer = 2
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 MilImageWatershed As MIL_ID = MIL.M_NULL
Dim lFetchedValue() As Integer = {0}
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilImageWatershed)
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilImage)
MIL.MdispSelect(MilDisplay, MilImage)
Console.Write(Constants.vbLf + "SEGMENTATION:" + Constants.vbLf)
Console.Write("-------------" + Constants.vbLf + Constants.vbLf)
Console.Write("An edge detection followed by a watershed will be used to remove" + Constants.vbLf)
Console.Write("the background." + Constants.vbLf + "Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MimEdgeDetect(MilImageWatershed, MilImageWatershed, MIL.M_NULL, MIL.M_SOBEL, MIL.M_REGULAR_EDGE_DETECT, MIL.M_NULL)
MIL.MimWatershed(MilImageWatershed, MIL.M_NULL, MilImageWatershed, WATERSHED_MINIMAL_GRADIENT_VARIATION, MIL.M_MINIMA_FILL + MIL.M_BASIN)
MIL.MbufGet2d(MilImageWatershed, PIXEL_FETCH_POSITION_X, PIXEL_FETCH_POSITION_Y, 1, 1, lFetchedValue)
MIL.MimClip(MilImageWatershed, MilImageWatershed, MIL.M_EQUAL, lFetchedValue(0), 0, 0, 0)
MIL.MimClip(MilImageWatershed, MilImage, MIL.M_NOT_EQUAL, 0, 0, &HFF, 0)
Console.Write("A distance transformation followed by a watershed will be used " + Constants.vbLf)
Console.Write("to separate the touching pills." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MimDistance(MilImage, MilImageWatershed, MIL.M_CHAMFER_3_4)
MIL.MimWatershed(MilImageWatershed, MIL.M_NULL, MilImageWatershed, WATERSHED_MINIMAL_DISTANCE_VARIATION, MIL.M_STRAIGHT_WATERSHED + MIL.M_MAXIMA_FILL + MIL.M_SKIP_LAST_LEVEL + MIL.M_WATERSHED)
MIL.MimArith(MilImageWatershed, MilImage, MilImage, MIL.M_AND)
Console.Write("Here are the segmented pills." + Constants.vbLf)
Console.Write("Press <Enter> to end." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MbufFree(MilImageWatershed)
MIL.MbufFree(MilImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Class
End Namespace