Exemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Fills the image buffer using MIL drawing.
        /// </summary>
        /// <param name="bufferSizeX">The width of the image buffer.</param>
        /// <param name="bufferSizeY">The height of the image buffer.</param>
        private void FillImageBuffer(MIL_INT bufferSizeX, MIL_INT bufferSizeY)
        {
            // Start by clearing the buffer
            MIL.MbufClear(_bufId, MIL.M_RGB888(0, 0, 0));

            // Fill the buffer with default content.
            MIL_INT defaultGraFont = MIL.MgraInquire(MIL.M_DEFAULT, MIL.M_FONT, MIL.M_NULL);

            MIL.MgraFont(MIL.M_DEFAULT, MIL.M_FONT_DEFAULT_LARGE);
            MIL.MgraText(MIL.M_DEFAULT, _bufId, ((bufferSizeX / 8) * 2), bufferSizeY / 2, " Welcome to MIL !!! ");
            MIL.MgraRect(MIL.M_DEFAULT, _bufId, ((bufferSizeX / 8) * 2) - 60, (bufferSizeY / 2) - 80, ((bufferSizeX / 8) * 2) + 370, (bufferSizeY / 2) + 100);
            MIL.MgraRect(MIL.M_DEFAULT, _bufId, ((bufferSizeX / 8) * 2) - 40, (bufferSizeY / 2) - 60, ((bufferSizeX / 8) * 2) + 350, (bufferSizeY / 2) + 80);
            MIL.MgraRect(MIL.M_DEFAULT, _bufId, ((bufferSizeX / 8) * 2) - 20, (bufferSizeY / 2) - 40, ((bufferSizeX / 8) * 2) + 330, (bufferSizeY / 2) + 60);
            MIL.MgraFont(MIL.M_DEFAULT, defaultGraFont);
        }
Exemplo n.º 2
0
        const int HALF_LUMINANCE  = 128;            // All colors have half luminance.

        // Creates a color display LUT to show defects in red.
        static void SetupColorDisplay(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_INT SizeBit)
        {
            MIL_ID  MilRampLut1Band   = MIL.M_NULL; // LUT containing hue values.
            MIL_ID  MilRampLut3Band   = MIL.M_NULL; // RGB LUT used by display.
            MIL_ID  MilColorImage     = MIL.M_NULL; // Image used for HSL to RGB conversion.
            MIL_INT DefectGrayLevel   = 0;          // Gray level under which all is red.
            MIL_INT ExpectedGrayLevel = 0;          // Gray level over which all is blue.
            MIL_INT NbGrayLevels;

            // Number of possible gray levels in corrected depth map.
            NbGrayLevels = (MIL_INT)(1 << (int)SizeBit);

            // Allocate 1-band LUT that will contain hue values.
            MIL.MbufAlloc1d(MilSystem, NbGrayLevels, 8 + MIL.M_UNSIGNED, MIL.M_LUT, ref MilRampLut1Band);

            // Compute limit gray values.
            DefectGrayLevel   = (MIL_INT)((EXPECTED_HEIGHT - SATURATED_DEFECT) * SCALE_FACTOR);
            ExpectedGrayLevel = (MIL_INT)(EXPECTED_HEIGHT * SCALE_FACTOR);

            // Create hue values for each possible gray level.
            MIL.MgenLutRamp(MilRampLut1Band, 0, RED_HUE, DefectGrayLevel, RED_HUE);
            MIL.MgenLutRamp(MilRampLut1Band, DefectGrayLevel, RED_HUE, ExpectedGrayLevel, BLUE_HUE);
            MIL.MgenLutRamp(MilRampLut1Band, ExpectedGrayLevel, BLUE_HUE, NbGrayLevels - 1, BLUE_HUE);

            // Create a HSL image buffer.
            MIL.MbufAllocColor(MilSystem, 3, NbGrayLevels, 1, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE, ref MilColorImage);
            MIL.MbufClear(MilColorImage, MIL.M_RGB888(0, FULL_SATURATION, HALF_LUMINANCE));

            // Set its H band (hue) to the LUT contents and convert the image to RGB.
            MIL.MbufCopyColor2d(MilRampLut1Band, MilColorImage, 0, 0, 0, 0, 0, 0, NbGrayLevels, 1);
            MIL.MimConvert(MilColorImage, MilColorImage, MIL.M_HSL_TO_RGB);

            // Create RGB LUT to give to display and copy image contents.
            MIL.MbufAllocColor(MilSystem, 3, NbGrayLevels, 1, 8 + MIL.M_UNSIGNED, MIL.M_LUT, ref MilRampLut3Band);
            MIL.MbufCopy(MilColorImage, MilRampLut3Band);

            // Associates LUT to display.
            MIL.MdispLut(MilDisplay, MilRampLut3Band);

            // Free all allocations.
            MIL.MbufFree(MilRampLut1Band);
            MIL.MbufFree(MilRampLut3Band);
            MIL.MbufFree(MilColorImage);
        }
Exemplo n.º 3
0
        //****************************************************************************
        // Draw the samples as color patches.
        static void DrawSampleColors(MIL_ID DestImage, MIL_INT[,] pSamplesColors, string[] pSampleNames, MIL_INT NumSamples, MIL_INT XSpacing, MIL_INT YOffset)
        {
            MIL_INT DestSizeX = MIL.MbufInquire(DestImage, MIL.M_SIZE_X, MIL.M_NULL);
            MIL_INT DestSizeY = MIL.MbufInquire(DestImage, MIL.M_SIZE_Y, MIL.M_NULL);
            double  OffsetX   = (DestSizeX - (NumSamples * COLOR_PATCH_SIZEX) - ((NumSamples - 1) * XSpacing)) / 2.0;
            double  OffsetY   = YOffset > 0 ? YOffset : (DestSizeY - COLOR_PATCH_SIZEY) / 2.0;
            double  TextOffsetX;

            MIL.MgraFont(MIL.M_DEFAULT, MIL.M_FONT_DEFAULT_SMALL);

            for (MIL_INT SampleIndex = 0; SampleIndex < NumSamples; SampleIndex++)
            {
                MIL.MgraColor(MIL.M_DEFAULT, MIL.M_RGB888((int)pSamplesColors[SampleIndex, 0], (int)pSamplesColors[SampleIndex, 1], (int)pSamplesColors[SampleIndex, 2]));
                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 += (COLOR_PATCH_SIZEX + XSpacing);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            MIL_ID MilApplication = MIL.M_NULL;                             // Application identifier.
            MIL_ID MilSystem      = MIL.M_NULL;                             // System identifier.
            MIL_ID MilDisplay     = MIL.M_NULL;                             // Display identifier.
            MIL_ID MilGraphicList = MIL.M_NULL;                             // graphic list identifier.

            MIL_ID[] MilSourceImages = new MIL_ID[NUM_IMAGES_TO_REGISTER];  // Source images buffer identifiers.
            MIL_ID   MilMosaicImage  = MIL.M_NULL;                          // Mosaic image buffer identifier.
            MIL_ID   MilRegContext   = MIL.M_NULL;                          // Registration context identifier.
            MIL_ID   MilRegResult    = MIL.M_NULL;                          // Registration result identifier.
            MIL_INT  Result          = 0;                                   // Result of the registration.
            MIL_INT  MosaicSizeX     = 0;                                   // Size of the mosaic.
            MIL_INT  MosaicSizeY     = 0;
            MIL_INT  MosaicSizeBand  = 0;                                   // Characteristics of mosaic image.
            MIL_INT  MosaicType      = 0;

            string[] ImageFilesSource = new string[NUM_IMAGES_TO_REGISTER];

            // Allocate defaults
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Load source image names.
            for (int i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
            {
                ImageFilesSource[i] = String.Format(IMAGE_FILES_SOURCE, i);
            }

            // Print module name.
            Console.Write("\nREGISTRATION MODULE:\n");
            Console.Write("---------------------\n\n");

            // Print comment.
            Console.Write("This program will make a mosaic from many source images.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Restore the source images.
            for (int i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
            {
                MIL.MbufRestore(ImageFilesSource[i], MilSystem, ref MilSourceImages[i]);
            }

            // Display the source images.
            for (int i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
            {
                MIL.MdispSelect(MilDisplay, MilSourceImages[i]);

                // Pause to show each image.
                Console.Write("image {0}.\n", i);
                Console.Write("Press <Enter> to continue.\n\n");
                Console.ReadKey();
            }

            // Allocate a graphic list to hold the subpixel annotations to draw.
            MIL.MgraAllocList(MilSystem, MIL.M_DEFAULT, ref MilGraphicList);
            MIL.MdispControl(MilDisplay, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, MilGraphicList);

            // Allocate a new empty registration context.
            MIL.MregAlloc(MilSystem, MIL.M_CORRELATION, MIL.M_DEFAULT, ref MilRegContext);

            // Allocate a new empty registration result buffer.
            MIL.MregAllocResult(MilSystem, MIL.M_DEFAULT, ref MilRegResult);

            // Set the transformation type to translation.
            MIL.MregControl(MilRegContext, MIL.M_CONTEXT, MIL.M_TRANSFORMATION_TYPE, MIL.M_TRANSLATION);

            // By default, each image will be registered with the previous in the list
            // No need to set other location parameters.

            // Set range to 100% in order to search all possible translations.
            MIL.MregControl(MilRegContext, MIL.M_CONTEXT, MIL.M_LOCATION_DELTA, 100);

            // Calculate the registration on the images.
            MIL.MregCalculate(MilRegContext, MilSourceImages, MilRegResult, NUM_IMAGES_TO_REGISTER, MIL.M_DEFAULT);

            // Verify if registration is successful.
            MIL.MregGetResult(MilRegResult, MIL.M_GENERAL, MIL.M_RESULT + MIL.M_TYPE_MIL_INT, ref Result);
            if (Result == MIL.M_SUCCESS)
            {
                // Get the size of the required mosaic buffer.
                MIL.MregGetResult(MilRegResult, MIL.M_GENERAL, MIL.M_MOSAIC_SIZE_X + MIL.M_TYPE_MIL_INT, ref MosaicSizeX);
                MIL.MregGetResult(MilRegResult, MIL.M_GENERAL, MIL.M_MOSAIC_SIZE_Y + MIL.M_TYPE_MIL_INT, ref MosaicSizeY);

                // The mosaic type will be the same as the source images.
                MIL.MbufInquire(MilSourceImages[0], MIL.M_SIZE_BAND, ref MosaicSizeBand);
                MIL.MbufInquire(MilSourceImages[0], MIL.M_TYPE, ref MosaicType);

                // Allocate mosaic image.
                MIL.MbufAllocColor(MilSystem, MosaicSizeBand, MosaicSizeX, MosaicSizeY, MosaicType, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ref MilMosaicImage);

                // Compose the mosaic from the source images.
                MIL.MregTransformImage(MilRegResult, MilSourceImages, MilMosaicImage, NUM_IMAGES_TO_REGISTER, MIL.M_BILINEAR + MIL.M_OVERSCAN_CLEAR, MIL.M_DEFAULT);

                // Display the mosaic image and prepare for overlay annotations.
                MIL.MdispSelect(MilDisplay, MilMosaicImage);
                MIL.MgraColor(MIL.M_DEFAULT, MIL.M_RGB888(0, 0xFF, 0));

                // Pause to show the mosaic.
                Console.Write("mosaic image.\n");
                Console.Write("Press <Enter> to continue.\n\n");
                Console.ReadKey();

                // Draw the box of all source images in the mosaic.
                MIL.MregDraw(MIL.M_DEFAULT, MilRegResult, MilGraphicList, MIL.M_DRAW_BOX, MIL.M_ALL, MIL.M_DEFAULT);

                // Draw a cross at the center of each image in the mosaic.
                for (int i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
                {
                    // Coordinates of the center of the source image.
                    double SourcePosX = 0.5 * (double)MIL.MbufInquire(MilSourceImages[i], MIL.M_SIZE_X, MIL.M_NULL);
                    double SourcePosY = 0.5 * (double)MIL.MbufInquire(MilSourceImages[i], MIL.M_SIZE_Y, MIL.M_NULL);

                    // Transform the coordinates to the mosaic.
                    double MosaicPosX = 0;
                    double MosaicPosY = 0;
                    MIL.MregTransformCoordinate(MilRegResult, i, MIL.M_MOSAIC, SourcePosX, SourcePosY, ref MosaicPosX, ref MosaicPosY, MIL.M_DEFAULT);
                    int MosaicPosXMilInt = (int)(MosaicPosX + 0.5);
                    int MosaicPosYMilInt = (int)(MosaicPosY + 0.5);

                    // Draw the cross in the mosaic.
                    MIL.MgraLine(MIL.M_DEFAULT, MilGraphicList, MosaicPosXMilInt - 4, MosaicPosYMilInt, MosaicPosXMilInt + 4, MosaicPosYMilInt);
                    MIL.MgraLine(MIL.M_DEFAULT, MilGraphicList, MosaicPosXMilInt, MosaicPosYMilInt - 4, MosaicPosXMilInt, MosaicPosYMilInt + 4);
                }

                Console.Write("The bounding boxes and the center of all source images\n");
                Console.Write("have been drawn in the mosaic.\n");
            }
            else
            {
                Console.Write("Error: Registration was not successful.\n");
            }

            // Pause to show results.
            Console.Write("\nPress <Enter> to end.\n\n");
            Console.ReadKey();

            // Free all allocations.
            MIL.MgraFree(MilGraphicList);
            if (MilMosaicImage != MIL.M_NULL)
            {
                MIL.MbufFree(MilMosaicImage);
            }

            MIL.MregFree(MilRegContext);
            MIL.MregFree(MilRegResult);

            for (int i = 0; i < NUM_IMAGES_TO_REGISTER; i++)
            {
                MIL.MbufFree(MilSourceImages[i]);
            }

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }