Example #1
0
        /// <summary>
        /// Executes specified filter on an image (without using parallel processor). As destination image size may be different from source; in-place filtering is not allowed.
        /// </summary>
        /// <param name="img">Image.</param>
        /// <param name="filter">AForge <see cref="BaseTransformationFilter"/>.</param>
        public static Image <TDstColor, TDepth> ApplyFilter <TSrcColor, TDepth, TDstColor>(this Image <TSrcColor, TDepth> img, BaseTransformationFilter filter)
            where TSrcColor : IColor
            where TDstColor : IColor
            where TDepth : struct
        {
            bool castOnly = img.CanCastToAForgeImage(); //we do not want to convert just cast

            if (castOnly == false)
            {
                throw new Exception("AForge filters can not be applied to this image format!");
            }

            //ToAforgeImage() will only cast image (cause the conversion path has been checked by CanCastOnlyToAForgeImage()
            var dest = filter.Apply(img.ToAForgeImage()).ToImage <TDstColor, TDepth>();

            return(dest);
        }
Example #2
0
        /// <summary>
        /// Executes specified filter on an image (without using parallel processor). As destination image size may be different from source; in-place filtering is not allowed.
        /// </summary>
        /// <param name="img">Image.</param>
        /// <param name="filter">AForge <see cref="BaseTransformationFilter"/>.</param>
        public static TDstColor[,] ApplyBaseTransformationFilter <TSrcColor, TDstColor>(this TSrcColor[,] img, BaseTransformationFilter filter)
        where TSrcColor : struct, IColor
        where TDstColor : struct, IColor
        {
            TDstColor[,] dest = new TDstColor[img.Height(), img.Width()];

            using (var uImg = img.Lock())
                using (var uDest = dest.Lock())
                {
                    filter.Apply(uImg.AsAForgeImage(), uDest.AsAForgeImage());
                }

            return(dest);
        }
Example #3
0
 /// <summary>
 /// Executes specified filter on an image (without using parallel processor). As destination image size may be different from source; in-place filtering is not allowed.
 /// </summary>
 /// <param name="img">Image.</param>
 /// <param name="filter">AForge <see cref="BaseTransformationFilter"/>.</param>
 public static Image <TColor, TDepth> ApplyFilter <TColor, TDepth>(this Image <TColor, TDepth> img, BaseTransformationFilter filter)
     where TColor : IColor
     where TDepth : struct
 {
     return(ApplyFilter <TColor, TDepth, TColor>(img, filter));
 }
Example #4
0
 /// <summary>
 /// Executes specified filter on an image (without using parallel processor). As destination image size may be different from source; in-place filtering is not allowed.
 /// </summary>
 /// <param name="img">Image.</param>
 /// <param name="filter">AForge <see cref="BaseTransformationFilter"/>.</param>
 public static TColor[,] ApplyBaseTransformationFilter <TColor>(this TColor[,] img, BaseTransformationFilter filter)
 where TColor : struct, IColor
 {
     return(ApplyFilter <TColor, BaseTransformationFilter>(img, filter));
 }