コード例 #1
0
        //==========================================================================================
        /// <summary>
        /// Changes the type of an image with the specified source, destination, type, and lookup table.
        /// </summary>
        /// <param name="source">
        /// The source image.
        /// </param>
        /// <param name="destination">
        /// The destination image. Set this parameter equal to source or <see langword="null"/> to perform the change directly on the source image.
        /// </param>
        /// <param name="type">
        /// The new type for the image. <paramref name="type"/> is the new type for the <paramref name="destination"/> image if it is being used, otherwise it is the new type for <paramref name="source"/>.
        /// </param>
        /// <param name="lookupTable">
        /// An optional lookup table. If you do not want  to use a lookup table, this parameter may be <see keyword="" keywordType="mstudio"/>.
        /// </param>

        public static void Cast(VisionImage source, VisionImage destination, ImageType type, Collection <float> lookupTable)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            source.ThrowIfDisposed();
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            destination.ThrowIfDisposed();
            int tableSize = 256;

            if (source.Type == ImageType.I16 || source.Type == ImageType.U16)
            {
                tableSize = 65536;
            }
            // If the table is the correct size, just do the conversion; otherwise, pad it first.
            float[] cviTable;
            if (lookupTable == null)
            {
                cviTable = null;
            }
            else
            {
                if (lookupTable.Count >= tableSize)
                {
                    cviTable = Utilities.ConvertCollectionToArray <float>(lookupTable);
                }
                else
                {
                    cviTable = new float[tableSize];
                    for (int i = 0; i < lookupTable.Count; ++i)
                    {
                        cviTable[i] = lookupTable[i];
                    }
                    for (int i = lookupTable.Count; i < tableSize; ++i)
                    {
                        if (source.Type == ImageType.I16)
                        {
                            cviTable[i] = (i <= 32768) ? (float)i : (float)(i - 65536);
                        }
                        else
                        {
                            cviTable[i] = i;
                        }
                    }
                }
            }
            Utilities.ThrowError(VisionDllCommon.imaqCast(destination._image, source._image, type, cviTable, 0));
        }
コード例 #2
0
        //==========================================================================================
        /// <summary>
        /// Changes the type of an image with the specified source, destination, type, and shifts.
        /// </summary>
        /// <param name="source">
        /// The source image.
        /// </param>
        /// <param name="destination">
        /// The destination image. Set this parameter equal to source or <see langword="null"/> to perform the change directly on the source image.
        /// </param>
        /// <param name="type">
        /// The new type for the image. <paramref name="type"/> is the new type for the <paramref name="destination"/> image if it is being used, otherwise it is the new type for <paramref name="source"/>.
        /// </param>
        /// <param name="numberOfShifts">
        /// The shift value for converting 16-bit images to 8-bit images. The method executes this conversion by shifting the 16-bit pixel values to the right by the specified number of shift operations, up to a maximum of 8 shift operations, and then truncating to get an 8-bit value. Enter a value of –1 to ignore the bit depth and shift 0. Enter a value of 0 to use the bit depth to cast the image.
        /// </param>

        public static void Cast(VisionImage source, VisionImage destination, ImageType type, Int32 numberOfShifts)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            source.ThrowIfDisposed();
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            destination.ThrowIfDisposed();
            Utilities.ThrowError(VisionDllCommon.imaqCast(destination._image, source._image, type, null, numberOfShifts));
        }