public static Image ToRegularImage(Image2D <double> image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            return(ToRegularImage(image, image.Min(), image.Max()));
        }
        public static Image ToRegularImage(Image2D <ObjectBackgroundTerm> image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            double min = image.Min(t => t.ObjectTerm - t.BackgroundTerm);
            double max = image.Max(t => t.ObjectTerm - t.BackgroundTerm);

            return(ToRegularImage(image, min, max));
        }
        public static Image ToRegularImage(Image2D <ObjectBackgroundTerm> image, double min, double max)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (max <= min)
            {
                throw new ArgumentException("Min should be less than max.");
            }

            double diff = max - min;

            return(ToRegularImage(image, x => ZeroOneToRedBlue((MathHelper.Trunc(x.ObjectTerm - x.BackgroundTerm, min, max) - min) / diff)));
        }
        private static Image ToRegularImage <T>(Image2D <T> image, Func <T, Color> converter)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            Bitmap result = new Bitmap(image.Width, image.Height);

            for (int i = 0; i < image.Width; ++i)
            {
                for (int j = 0; j < image.Height; ++j)
                {
                    result.SetPixel(i, j, converter(image[i, j]));
                }
            }
            return(result);
        }
        public static Image2D <Color> FromRegularImage(Bitmap image, double scaleCoeff)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            using (Bitmap scaledImage = new Bitmap(
                       image,
                       (int)Math.Round(image.Width * scaleCoeff),
                       (int)Math.Round(image.Height * scaleCoeff)))
            {
                Image2D <Color> result = new Image2D <Color>(scaledImage.Width, scaledImage.Height);
                for (int x = 0; x < scaledImage.Width; ++x)
                {
                    for (int y = 0; y < scaledImage.Height; ++y)
                    {
                        result[x, y] = scaledImage.GetPixel(x, y);
                    }
                }

                return(result);
            }
        }
 public static Image ToRegularImage(Image2D <bool?> image)
 {
     return(ToRegularImage(image, x => x.HasValue ? (x.Value ? Color.Red : Color.Blue) : Color.Black));
 }
 public static void SaveToFile(Image2D <ObjectBackgroundTerm> image, string fileName)
 {
     ToRegularImage(image).Save(fileName);
 }
 public static void SaveToFile(Image2D <double> image, string fileName)
 {
     ToRegularImage(image).Save(fileName);
 }
 public static void SaveToFile(Image2D <double> image, double min, double max, string fileName)
 {
     ToRegularImage(image, min, max).Save(fileName);
 }
 public static Image ToRegularImage(Image2D <bool> image)
 {
     return(ToRegularImage(image, x => x ? Color.White : Color.Black));
 }
 public static Image ToRegularImage(Image2D <Color> image)
 {
     return(ToRegularImage(image, x => x));
 }