示例#1
0
        /// <summary>
        /// Sets the specified value for only those element of the array where the mask is non-zero.
        /// </summary>
        /// <typeparam name="T">Element type.</typeparam>
        /// <param name="array">Array with value type elements.</param>
        /// <param name="value">Value to set.</param>
        /// <param name="mask">Mask.</param>
        public static void SetValue <T>(this T[,] array, T value, Gray <byte>[,] mask)
        {
            if (array.Size() != mask.Size())
            {
                throw new ArgumentException("Array and mask must have the same size.");
            }

            ParallelLauncher.Launch((thread) =>
            {
                if (mask[thread.Y, thread.X] != 0)
                {
                    array[thread.Y, thread.X] = value;
                }
            },
                                    array.Width(), array.Height());
        }
示例#2
0
        /// <summary>
        /// Copies values from source to destination image using mask. Destination values where mask == 0 are not erased!.
        /// </summary>
        /// <param name="source">Image.</param>
        /// <param name="destination">Destination image</param>
        /// <param name="mask">Mask. Color locations that need to be copied must be set to !=0 in mask.</param>
        public static void CopyTo <TColor>(this TColor[,] source, TColor[,] destination, Gray <byte>[,] mask)
            where TColor : struct
        {
            if (source.Size() != mask.Size() || source.Size() != destination.Size())
            {
                throw new Exception("Image, mask, destImg size must be the same!");
            }

            ParallelLauncher.Launch((thread) =>
            {
                if (mask[thread.Y, thread.X] != 0)
                {
                    destination[thread.Y, thread.X] = source[thread.Y, thread.X];
                }
            },
                                    source.Width(), source.Height());
        }