'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MReg
Friend Class Program
Private Const NUM_IMAGES_TO_REGISTER As Integer = 3
Private Const IMAGE_FILES_SOURCE As String = MIL.M_IMAGE_PATH & "CircuitBoardPart{0}.mim"
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 MilGraphicList As MIL_ID = MIL.M_NULL
Dim MilSourceImages(NUM_IMAGES_TO_REGISTER - 1) As MIL_ID
Dim MilMosaicImage As MIL_ID = MIL.M_NULL
Dim MilRegContext As MIL_ID = MIL.M_NULL
Dim MilRegResult As MIL_ID = MIL.M_NULL
Dim Result As MIL_INT = 0
Dim MosaicSizeX As MIL_INT = 0
Dim MosaicSizeY As MIL_INT = 0
Dim MosaicSizeBand As MIL_INT = 0
Dim MosaicType As MIL_INT = 0
Dim ImageFilesSource(NUM_IMAGES_TO_REGISTER - 1) As String
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
For i As Integer = 0 To NUM_IMAGES_TO_REGISTER - 1
ImageFilesSource(i) = String.Format(IMAGE_FILES_SOURCE, i)
Next i
Console.Write(Constants.vbLf + "REGISTRATION MODULE:" + Constants.vbLf)
Console.Write("---------------------" + Constants.vbLf + Constants.vbLf)
Console.Write("This program will make a mosaic from many source images." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
For i As Integer = 0 To NUM_IMAGES_TO_REGISTER - 1
MIL.MbufRestore(ImageFilesSource(i), MilSystem, MilSourceImages(i))
Next i
For i As Integer = 0 To NUM_IMAGES_TO_REGISTER - 1
MIL.MdispSelect(MilDisplay, MilSourceImages(i))
Console.Write("image {0}." + Constants.vbLf, i)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
Next i
MIL.MgraAllocList(MilSystem, MIL.M_DEFAULT, MilGraphicList)
MIL.MdispControl(MilDisplay, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, MilGraphicList)
MIL.MregAlloc(MilSystem, MIL.M_STITCHING, MIL.M_DEFAULT, MilRegContext)
MIL.MregAllocResult(MilSystem, MIL.M_DEFAULT, MilRegResult)
MIL.MregControl(MilRegContext, MIL.M_CONTEXT, MIL.M_TRANSFORMATION_TYPE, MIL.M_TRANSLATION)
MIL.MregControl(MilRegContext, MIL.M_CONTEXT, MIL.M_LOCATION_DELTA, 100)
MIL.MregCalculate(MilRegContext, MilSourceImages, MilRegResult, NUM_IMAGES_TO_REGISTER, MIL.M_DEFAULT)
MIL.MregGetResult(MilRegResult, MIL.M_GENERAL, MIL.M_RESULT + MIL.M_TYPE_MIL_INT, Result)
If Result = MIL.M_SUCCESS Then
MIL.MregGetResult(MilRegResult, MIL.M_GENERAL, MIL.M_MOSAIC_SIZE_X + MIL.M_TYPE_MIL_INT, MosaicSizeX)
MIL.MregGetResult(MilRegResult, MIL.M_GENERAL, MIL.M_MOSAIC_SIZE_Y + MIL.M_TYPE_MIL_INT, MosaicSizeY)
MIL.MbufInquire(MilSourceImages(0), MIL.M_SIZE_BAND, MosaicSizeBand)
MIL.MbufInquire(MilSourceImages(0), MIL.M_TYPE, MosaicType)
MIL.MbufAllocColor(MilSystem, MosaicSizeBand, MosaicSizeX, MosaicSizeY, MosaicType, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, MilMosaicImage)
MIL.MregTransformImage(MilRegResult, MilSourceImages, MilMosaicImage, NUM_IMAGES_TO_REGISTER, MIL.M_BILINEAR + MIL.M_OVERSCAN_CLEAR, MIL.M_DEFAULT)
MIL.MdispSelect(MilDisplay, MilMosaicImage)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_RGB888(0, &HFF, 0))
Console.Write("mosaic image." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MregDraw(MIL.M_DEFAULT, MilRegResult, MilGraphicList, MIL.M_DRAW_BOX, MIL.M_ALL, MIL.M_DEFAULT)
For i As Integer = 0 To NUM_IMAGES_TO_REGISTER - 1
Dim SourcePosX As Double = 0.5 * CDbl(MIL.MbufInquire(MilSourceImages(i), MIL.M_SIZE_X, MIL.M_NULL))
Dim SourcePosY As Double = 0.5 * CDbl(MIL.MbufInquire(MilSourceImages(i), MIL.M_SIZE_Y, MIL.M_NULL))
Dim MosaicPosX As Double = 0
Dim MosaicPosY As Double = 0
MIL.MregTransformCoordinate(MilRegResult, i, MIL.M_MOSAIC, SourcePosX, SourcePosY, MosaicPosX, MosaicPosY, MIL.M_DEFAULT)
Dim MosaicPosXMilInt As Integer = CInt(Fix(MosaicPosX + 0.5))
Dim MosaicPosYMilInt As Integer = CInt(Fix(MosaicPosY + 0.5))
MIL.MgraLine(MIL.M_DEFAULT, MilGraphicList, MosaicPosXMilInt - 4, MosaicPosYMilInt, MosaicPosXMilInt + 4, MosaicPosYMilInt)
MIL.MgraLine(MIL.M_DEFAULT, MilGraphicList, MosaicPosXMilInt, MosaicPosYMilInt - 4, MosaicPosXMilInt, MosaicPosYMilInt + 4)
Next i
Console.Write("The bounding boxes and the center of all source images" + Constants.vbLf)
Console.Write("have been drawn in the mosaic." + Constants.vbLf)
Else
Console.Write("Error: Registration was not successful." + Constants.vbLf)
End If
Console.Write(Constants.vbLf + "Press <Enter> to end." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MgraFree(MilGraphicList)
If MilMosaicImage <> MIL.M_NULL Then
MIL.MbufFree(MilMosaicImage)
End If
MIL.MregFree(MilRegContext)
MIL.MregFree(MilRegResult)
For i As Integer = 0 To NUM_IMAGES_TO_REGISTER - 1
MIL.MbufFree(MilSourceImages(i))
Next i
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Class
End Namespace