예제 #1
0
        static void Main(string[] args)
        {
            var OriginalPath = args[0];

            var Original = new Bitmap(OriginalPath);

            var Converted = new Bitmap(Original.Width, Original.Height, PixelFormat.Format1bppIndexed);

            double average = 0.5;
            double sigma = 0.1;
            if (args.Length > 2)
            {
                average = double.Parse(args[1]);
                if (args.Length == 3)
                    sigma = double.Parse(args[2]);
                else
                    throw new ArgumentException("Too Many Options!");
            }

            Stopwatch sw = new Stopwatch();
            sw.Start();

            int Width = Original.Width, Height = Original.Height;
            using (var proc = new BmpProc1(Converted))
            {
                double alpha, beta;

                double b;
                using (var proc_original = new BmpProc32(Original))
                    for (int y = 0; y < Height; ++y)
                    {
                        for (int x = 0; x < Width; ++x)
                        {
                            b = proc_original[x, y].GetBrightness();
                            alpha = rand.NextDouble();
                            beta = rand.NextDouble();
                            b += sigma * Math.Sqrt(-2 * Math.Log(alpha)) * Math.Cos(2 * Math.PI * beta);
                            if (b > average)
                                proc[x, y] = true;
                            else
                                proc[x, y] = false;
                        }
                    }
                Original.Dispose();
            }
            sw.Stop();
            Console.WriteLine("{0} Seconds.", sw.Elapsed.TotalSeconds);
            var SaveFileName = Path.Combine(Path.GetDirectoryName(OriginalPath), Path.GetFileNameWithoutExtension(OriginalPath) + "_mono.bmp");
            Converted.Save(SaveFileName, ImageFormat.Bmp);
            Converted.Dispose();
        }
예제 #2
0
        private void ConvertClick(object sender, EventArgs e)
        {
            if (this.Original == null)
                return;
            Converted = new Bitmap(Original.Width, Original.Height, PixelFormat.Format1bppIndexed);

            Stopwatch sw = new Stopwatch();
            sw.Start();

            int Width = Original.Width, Height = Original.Height;
            using (var proc = new BmpProc1(Converted))
            {
                double alpha, beta;

                {
                    double b;
                    using (var proc_original = new BmpProc32(Original))
                        for (int y = 0; y < Height; ++y)
                        {
                            for (int x = 0; x < Width; ++x)
                            {
                                b = proc_original[x, y].GetBrightness();
                                alpha = rand.NextDouble();
                                beta = rand.NextDouble();
                                b += this.b_sigma * Math.Sqrt(-2 * Math.Log(alpha)) * Math.Cos(2 * Math.PI * beta);
                                if (b > this.b_average)
                                    proc[x, y] = true;
                                else
                                    proc[x, y] = false;
                            }
                        }
                }
            }
            sw.Stop();
            this.pictureBox1.Image = Converted;
            MessageBox.Show(string.Format("{0}秒", sw.Elapsed.TotalSeconds));
        }
예제 #3
0
 private unsafe void feedbackToolStripMenuItem_Click(object sender, EventArgs e)
 {
     double b;
     using (var proc_original = new BmpProc32(Original))
     {
         for (int y = 0; y < Height; ++y)
         {
             for (int x = 0; x < Width; ++x)
             {
                 b = proc_original.GetPixel(x, y).GetBrightness();
                 b_average += b;
                 b_sigma += b * b;
             }
         }
         b_average /= Width * Height;
         b_sigma = Math.Sqrt(b_sigma / (Width * Height) - b_average * b_average);
     }
 }