/// <summary>
        /// Executes the user defined two source filter operation.
        /// </summary>
        /// <typeparam name="TColor">Image color.</typeparam>
        /// <param name="imageA">First image.</param>
        /// <param name="imageB">Second image.</param>
        /// <param name="func">User defined operation.</param>
        /// <param name="inPlace">If true the result is going to be stored in the first image. If false a new image is going to be created.</param>
        /// <returns>he result image. If <paramref name="inPlace"/> is set to true, the return value can be discarded.</returns>
        public static TColor[,] Calculate <TColor>(this TColor[,] imageA, TColor[,] imageB, TwoSourceFilterFunc <TColor> func, bool inPlace = false)
        where TColor : struct
        {
            TColor[,] dest = imageA;
            if (!inPlace)
            {
                dest = imageA.CopyBlank();
            }

            ParallelLauncher.Launch(thread =>
            {
                func(ref imageA[thread.Y, thread.X], ref imageB[thread.Y, thread.X], ref dest[thread.Y, thread.X]);
            },
                                    imageA.Width(), imageA.Height());

            return(dest);
        }
예제 #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());
        }
        /// <summary>
        /// Replaces real channel with the specified one.
        /// </summary>
        /// <param name="source">Source image.</param>
        /// <param name="value">The matrix which replaces the real channel of a source.</param>
        /// <param name="sourceArea">Source working area.</param>
        public static void ReplaceRe(this ComplexF[,] source, float[,] value, Rectangle sourceArea)
        {
            if (source.Width() > sourceArea.Right ||
                source.Height() > sourceArea.Bottom ||
                sourceArea.X < 0 ||
                sourceArea.Y < 0)
            {
                throw new ArgumentException("Source area must fit within the source image.");
            }

            if (value.Width() != sourceArea.Width ||
                value.Height() != sourceArea.Height)
            {
                throw new ArgumentException("Value size must be the same as source area size.");
            }

            ParallelLauncher.Launch(thread =>
            {
                source[thread.Y + sourceArea.Y, thread.X + sourceArea.X].Re = value[thread.Y, thread.X];
            },
                                    sourceArea.Width, sourceArea.Height);
        }