コード例 #1
0
        public static Image ToRegularImage(Image2D <double> image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            return(ToRegularImage(image, image.Min(), image.Max()));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
 public static Image ToRegularImage(Image2D <bool?> image)
 {
     return(ToRegularImage(image, x => x.HasValue ? (x.Value ? Color.Red : Color.Blue) : Color.Black));
 }
コード例 #7
0
 public static void SaveToFile(Image2D <ObjectBackgroundTerm> image, string fileName)
 {
     ToRegularImage(image).Save(fileName);
 }
コード例 #8
0
 public static void SaveToFile(Image2D <double> image, string fileName)
 {
     ToRegularImage(image).Save(fileName);
 }
コード例 #9
0
 public static void SaveToFile(Image2D <double> image, double min, double max, string fileName)
 {
     ToRegularImage(image, min, max).Save(fileName);
 }
コード例 #10
0
 public static Image ToRegularImage(Image2D <bool> image)
 {
     return(ToRegularImage(image, x => x ? Color.White : Color.Black));
 }
コード例 #11
0
 public static Image ToRegularImage(Image2D <Color> image)
 {
     return(ToRegularImage(image, x => x));
 }