Exemplo n.º 1
0
 // 增加椒鹽雜訊(黑白雜訊)
 private void button1_Click(object sender, EventArgs e)
 {
     pcxAfter.SaltPepper();
     pictureBox2.Image = pcxAfter.pcxImg;
     // 顯示SNR值 (到小數後2位)
     textBox1.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
 }
Exemplo n.º 2
0
 // 放大(複製)
 private void button1_Click(object sender, EventArgs e)
 {
     pcxAfter = new ImgPcx(pcxOrigin);
     pcxAfter.ZoomIn_Duplication(Double.Parse(textBox1.Text));
     pictureBox1.Image = pcxAfter.pcxImg;
     // 顯示SNR值 (到小數後2位)
     textBox2.Text = pcxOrigin.GetSNR(pcxOrigin, pcxAfter).ToString("f2");
 }
Exemplo n.º 3
0
 private void FormHighBoost_Load(object sender, EventArgs e)
 {
     pictureBox1.Image = pcxGray.pcxImg;
     pcxAfter          = new ImgPcx(pcxGray);
     pcxAfter.HighBoost(1.0);
     pictureBox2.Image = pcxAfter.pcxImg;
     // 顯示SNR值 (到小數後2位)
     textBox1.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
 }
Exemplo n.º 4
0
 private void FormRoberts_Load(object sender, EventArgs e)
 {
     pictureBox1.Image    = pcxGray.pcxImg;
     radioButton1.Checked = true;
     pcxAfter             = new ImgPcx(pcxGray);
     pcxAfter.Roberts("vertical");
     pictureBox2.Image = pcxAfter.pcxImg;
     // 顯示SNR值 (到小數後2位)
     textBox1.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
 }
Exemplo n.º 5
0
 private void radioButton1_CheckedChanged(object sender, EventArgs e)
 {
     if (radioButton1.Checked == true)
     {
         textBox1.Text = mask1;
         pcxAfter      = new ImgPcx(pcxGray);
         pcxAfter.EdgeCrispening("mask1");
         pictureBox2.Image = pcxAfter.pcxImg;
         // 顯示SNR值 (到小數後2位)
         textBox2.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
     }
 }
Exemplo n.º 6
0
 private void FormRGB_Load(object sender, EventArgs e)
 {
     pcxR = new ImgPcx(pcxOrigin);
     pcxG = new ImgPcx(pcxOrigin);
     pcxB = new ImgPcx(pcxOrigin);
     pcxR.R_Plane();
     pcxG.G_Plane();
     pcxB.B_Plane();
     // 顯示SNR值
     textBox1.Text     = pcxOrigin.GetSNR(pcxOrigin, pcxR).ToString("f2");
     textBox2.Text     = pcxOrigin.GetSNR(pcxOrigin, pcxG).ToString("f2");
     textBox3.Text     = pcxOrigin.GetSNR(pcxOrigin, pcxB).ToString("f2");
     pictureBox1.Image = pcxR.pcxImg;
     pictureBox2.Image = pcxG.pcxImg;
     pictureBox3.Image = pcxB.pcxImg;
 }
Exemplo n.º 7
0
        private void FormGray_Load(object sender, EventArgs e)
        {
            // 灰階
            try
            {
                pictureBox1.Image = pcxOrigin.pcxImg;
                pcxAfter          = new ImgPcx(pcxOrigin);
                pcxAfter.Gray();
                pictureBox2.Image = pcxAfter.pcxImg;

                // 顯示SNR值 (到小數後2位)
                textBox1.Text = pcxOrigin.GetSNR(pcxOrigin, pcxAfter).ToString("f2");

                // 清除圖表資料
                chart1.Series.Clear();
                // 設定圖表的高度與圖片相同
                chart1.Size = new Size(chart1.Width, pictureBox1.Image.Height);

                // 繪製histogram
                Bitmap   origin  = (Bitmap)pictureBox2.Image;
                Bitmap   target  = origin.Clone(new Rectangle(0, 0, origin.Width, origin.Height), PixelFormat.Format24bppRgb);
                int      w       = target.Width;
                int      h       = target.Height;
                double[] yValue1 = new double[256];
                Array.Clear(yValue1, 0, yValue1.Length);
                for (int x = 0; x < w; ++x)
                {
                    for (int y = 0; y < h; ++y)
                    {
                        Color c = target.GetPixel(x, y);
                        int   r = c.R;
                        int   g = c.G;
                        int   b = c.B;
                        ++yValue1[r];
                        ++yValue1[g];
                        ++yValue1[b];
                    }
                }
                // 將點個數轉換為頻率
                int total = w * h * 3;
                for (int i = 0; i < 256; ++i)
                {
                    yValue1[i] /= total;
                }

                // Range(start, cnt)
                string[] xValue = Enumerable.Range(0, 256).ToArray().Select(x => x.ToString()).ToArray();
                // 設定x軸區間
                chart1.ChartAreas["ChartArea1"].AxisX.Interval = 32;
                // Intensities - 強度
                chart1.Series.Add("Intensities");                                // 資料序列集合
                chart1.Series["Intensities"].ChartType = SeriesChartType.Column; // 直方圖
                chart1.Series["Intensities"].Points.DataBindXY(xValue, yValue1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 8
0
        private void FormThreshold_Load(object sender, EventArgs e)
        {
            // 顯示FormMain傳來ImgPcx物件的圖片 (原始圖片)
            pictureBox1.Image = pcxGray.pcxImg;
            pcxAfter          = new ImgPcx(pcxGray);
            // 初始值為0
            pcxAfter.Threshold(0);
            pictureBox2.Image = pcxAfter.pcxImg;

            // 顯示SNR值 (到小數後2位)
            textBox2.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");

            // 清除圖表資料
            chart1.Series.Clear();
            chart1.ChartAreas["ChartArea1"].AxisX.StripLines.Clear();
            // 設定圖表的高度與圖片相同
            chart1.Size = new Size(chart1.Width, pictureBox1.Image.Height);

            // 繪製histogram
            Bitmap origin = (Bitmap)pictureBox2.Image;
            Bitmap target = origin.Clone(new Rectangle(0, 0, origin.Width, origin.Height), PixelFormat.Format24bppRgb);
            int    w      = target.Width;
            int    h      = target.Height;

            double[] yValue1 = new double[256];
            Array.Clear(yValue1, 0, yValue1.Length);
            for (int x = 0; x < w; ++x)
            {
                for (int y = 0; y < h; ++y)
                {
                    Color c = target.GetPixel(x, y);
                    int   r = c.R;
                    int   g = c.G;
                    int   b = c.B;
                    ++yValue1[r];
                    ++yValue1[g];
                    ++yValue1[b];
                }
            }
            // 將點個數轉換為頻率
            int total = w * h * 3;

            for (int i = 0; i < 256; ++i)
            {
                yValue1[i] /= total;
            }

            // Range(start, cnt)
            string[] xValue = Enumerable.Range(0, 256).ToArray().Select(x => x.ToString()).ToArray();
            // 設定x軸區間
            chart1.ChartAreas["ChartArea1"].AxisX.Interval = 32;
            // Intensities - 強度
            chart1.Series.Add("Intensities");                                       // 資料序列集合
            chart1.Series["Intensities"].ChartType        = SeriesChartType.Column; // 直方圖
            chart1.ChartAreas["ChartArea1"].AxisY.Maximum = 1;
            chart1.ChartAreas["ChartArea1"].AxisY.Minimum = 0;
            chart1.Series["Intensities"].Points.DataBindXY(xValue, yValue1);
            chart1.Series["Intensities"].Color = Color.Blue;

            // 畫出threshold
            StripLine stripline = new StripLine();

            stripline.Interval       = 0;
            stripline.IntervalOffset = 0;
            stripline.StripWidth     = 1;
            stripline.BackColor      = Color.Red;
            chart1.ChartAreas["ChartArea1"].AxisX.StripLines.Add(stripline);
        }
Exemplo n.º 9
0
        private void FormHistEqual_Load(object sender, EventArgs e)
        {
            // 原灰階圖
            pictureBox1.Image = pcxGray.pcxImg;
            // 繪製原灰階圖直方圖
            // 清除圖表資料
            chart1.Series.Clear();
            // 設定圖表的高度與圖片相同
            chart1.Size = new Size(chart1.Width, pictureBox1.Image.Height);
            // 繪製histogram
            Bitmap target = pcxGray.pcxImg.Clone(new Rectangle(0, 0, pcxGray.pcxImg.Width, pcxGray.pcxImg.Height), PixelFormat.Format24bppRgb);
            int    w      = target.Width;
            int    h      = target.Height;

            Array.Clear(yValue1, 0, yValue1.Length);
            for (int x = 0; x < w; ++x)
            {
                for (int y = 0; y < h; ++y)
                {
                    Color c = target.GetPixel(x, y);
                    int   r = c.R;
                    int   g = c.G;
                    int   b = c.B;
                    ++yValue1[r];
                    ++yValue1[g];
                    ++yValue1[b];
                }
            }
            // 保存轉換成頻率前的統計結果
            Array.Copy(yValue1, hist, yValue1.Length);
            // 將點個數轉換為頻率
            int total = w * h * 3;

            for (int i = 0; i < 256; ++i)
            {
                yValue1[i] /= total;
            }
            // 設定x軸區間
            chart1.ChartAreas["ChartArea1"].AxisX.Interval = 32;
            // Intensities - 強度
            chart1.Series.Add("Intensities");                                // 資料序列集合
            chart1.Series["Intensities"].ChartType = SeriesChartType.Column; // 直方圖
            chart1.Series["Intensities"].Points.DataBindXY(xValue, yValue1);
            // 保存原始縱軸最大值
            originYMax = chart1.ChartAreas["ChartArea1"].AxisY.Maximum;

            // Histogram Equalization
            pcxAfter = new ImgPcx(pcxGray);
            pcxAfter.HistEqual(hist);
            pictureBox2.Image = pcxAfter.pcxImg;

            // 顯示SNR值 (到小數後2位)
            textBox1.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");

            // 繪製Histogram Equalization後的直方圖
            chart2.Series.Clear();
            chart2.Size = chart1.Size;
            target      = pcxAfter.pcxImg.Clone(new Rectangle(0, 0, pcxAfter.pcxImg.Width, pcxAfter.pcxImg.Height), PixelFormat.Format24bppRgb);
            Array.Clear(yValue2, 0, yValue2.Length);
            for (int x = 0; x < w; ++x)
            {
                for (int y = 0; y < h; ++y)
                {
                    Color c = target.GetPixel(x, y);
                    int   r = c.R;
                    int   g = c.G;
                    int   b = c.B;
                    ++yValue2[r];
                    ++yValue2[g];
                    ++yValue2[b];
                }
            }
            // 將點個數轉換為頻率
            for (int i = 0; i < 256; ++i)
            {
                yValue2[i] /= total;
            }
            // 設定x軸區間
            chart2.ChartAreas["ChartArea1"].AxisX.Interval = 32;
            // Intensities - 強度
            chart2.Series.Add("Intensities");                                // 資料序列集合
            chart2.Series["Intensities"].ChartType = SeriesChartType.Column; // 直方圖
            chart2.Series["Intensities"].Points.DataBindXY(xValue, yValue2);
        }
Exemplo n.º 10
0
        private void FormInvert_Load(object sender, EventArgs e)
        {
            try
            {
                // RGB
                pictureBox1.Image = pcxOrigin.pcxImg;
                pcxAfter          = new ImgPcx(pcxOrigin);
                // 負片
                pcxAfter.Invert();
                pictureBox2.Image = pcxAfter.pcxImg;

                // 顯示SNR值 (到小數後2位)
                textBox1.Text = pcxOrigin.GetSNR(pcxOrigin, pcxAfter).ToString("f2");

                // 灰階
                pictureBox3.Image = pcxGray.pcxImg;
                pcxAfter          = new ImgPcx(pcxGray);
                // 負片
                pcxAfter.Invert();
                pictureBox4.Image = pcxAfter.pcxImg;

                // 顯示SNR值 (到小數後2位)
                textBox2.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");

                // 繪製histogram
                // 設定圖表的高度與圖片相同
                chart1.Size = new Size(chart1.Width, pictureBox1.Image.Height);
                Bitmap   origin  = (Bitmap)pictureBox1.Image;
                Bitmap   target  = origin.Clone(new Rectangle(0, 0, origin.Width, origin.Height), PixelFormat.Format24bppRgb);
                int      w       = target.Width;
                int      h       = target.Height;
                double[] yValue1 = new double[256];
                double[] yValue2 = new double[256];
                double[] yValue3 = new double[256];
                Array.Clear(yValue1, 0, yValue1.Length);
                Array.Clear(yValue2, 0, yValue2.Length);
                Array.Clear(yValue3, 0, yValue3.Length);
                for (int x = 0; x < w; ++x)
                {
                    for (int y = 0; y < h; ++y)
                    {
                        Color c = target.GetPixel(x, y);
                        int   r = c.R;
                        int   g = c.G;
                        int   b = c.B;
                        ++yValue1[r];
                        ++yValue2[g];
                        ++yValue3[b];
                    }
                }
                // 將點個數轉換為頻率
                int total = w * h * 3;
                for (int i = 0; i < 256; ++i)
                {
                    yValue1[i] /= total;
                    yValue2[i] /= total;
                    yValue3[i] /= total;
                }

                // Range(start, cnt)
                string[] xValue = Enumerable.Range(0, 256).ToArray().Select(x => x.ToString()).ToArray();
                // 設定x軸區間
                chart1.ChartAreas["ChartArea1"].AxisX.Interval = 32;
                chart1.Series.Add("R");
                chart1.Series.Add("G");
                chart1.Series.Add("B");
                chart1.Series["R"].ChartType = SeriesChartType.Column;
                chart1.Series["R"].Points.DataBindXY(xValue, yValue1);
                chart1.Series["R"].Color     = Color.FromArgb(150, Color.Red); // 半透明顏色
                chart1.Series["G"].ChartType = SeriesChartType.Column;
                chart1.Series["G"].Points.DataBindXY(xValue, yValue2);
                chart1.Series["G"].Color     = Color.FromArgb(150, Color.Green);
                chart1.Series["B"].ChartType = SeriesChartType.Column;
                chart1.Series["B"].Points.DataBindXY(xValue, yValue3);
                chart1.Series["B"].Color = Color.FromArgb(150, Color.Blue);

                // 設定圖表的高度與圖片相同
                chart2.Size = new Size(chart2.Width, pictureBox2.Image.Height);
                origin      = (Bitmap)pictureBox2.Image;
                target      = origin.Clone(new Rectangle(0, 0, origin.Width, origin.Height), PixelFormat.Format24bppRgb);
                w           = target.Width;
                h           = target.Height;
                Array.Clear(yValue1, 0, yValue1.Length);
                Array.Clear(yValue2, 0, yValue2.Length);
                Array.Clear(yValue3, 0, yValue3.Length);
                for (int x = 0; x < w; ++x)
                {
                    for (int y = 0; y < h; ++y)
                    {
                        Color c = target.GetPixel(x, y);
                        int   r = c.R;
                        int   g = c.G;
                        int   b = c.B;
                        ++yValue1[r];
                        ++yValue2[g];
                        ++yValue3[b];
                    }
                }
                // 將點個數轉換為頻率
                total = w * h * 3;
                for (int i = 0; i < 256; ++i)
                {
                    yValue1[i] /= total;
                    yValue2[i] /= total;
                    yValue3[i] /= total;
                }
                // 設定x軸區間
                chart2.ChartAreas["ChartArea1"].AxisX.Interval = 32;
                chart2.Series.Add("R");
                chart2.Series.Add("G");
                chart2.Series.Add("B");
                chart2.Series["R"].ChartType = SeriesChartType.Column;
                chart2.Series["R"].Points.DataBindXY(xValue, yValue1);
                chart2.Series["R"].Color     = Color.FromArgb(150, Color.Red); // 半透明顏色
                chart2.Series["G"].ChartType = SeriesChartType.Column;
                chart2.Series["G"].Points.DataBindXY(xValue, yValue2);
                chart2.Series["G"].Color     = Color.FromArgb(150, Color.Green);
                chart2.Series["B"].ChartType = SeriesChartType.Column;
                chart2.Series["B"].Points.DataBindXY(xValue, yValue3);
                chart2.Series["B"].Color = Color.FromArgb(150, Color.Blue);

                // 設定圖表的高度與圖片相同
                chart3.Size = new Size(chart3.Width, pictureBox3.Image.Height);
                origin      = (Bitmap)pictureBox3.Image;
                target      = origin.Clone(new Rectangle(0, 0, origin.Width, origin.Height), PixelFormat.Format24bppRgb);
                w           = target.Width;
                h           = target.Height;
                Array.Clear(yValue1, 0, yValue1.Length);
                for (int x = 0; x < w; ++x)
                {
                    for (int y = 0; y < h; ++y)
                    {
                        Color c = target.GetPixel(x, y);
                        int   r = c.R;
                        int   g = c.G;
                        int   b = c.B;
                        ++yValue1[r];
                        ++yValue1[g];
                        ++yValue1[b];
                    }
                }
                // 將點個數轉換為頻率
                total = w * h * 3;
                for (int i = 0; i < 256; ++i)
                {
                    yValue1[i] /= total;
                }
                // 設定x軸區間
                chart3.ChartAreas["ChartArea1"].AxisX.Interval = 32;
                // Intensities - 強度
                chart3.Series.Add("Intensities"); // 資料序列集合
                chart3.Series["Intensities"].ChartType = SeriesChartType.Column;
                chart3.Series["Intensities"].Points.DataBindXY(xValue, yValue1);

                // 設定圖表的高度與圖片相同
                chart4.Size = new Size(chart4.Width, pictureBox4.Image.Height);
                origin      = (Bitmap)pictureBox4.Image;
                target      = origin.Clone(new Rectangle(0, 0, origin.Width, origin.Height), PixelFormat.Format24bppRgb);
                w           = target.Width;
                h           = target.Height;
                Array.Clear(yValue1, 0, yValue1.Length);
                for (int x = 0; x < w; ++x)
                {
                    for (int y = 0; y < h; ++y)
                    {
                        Color c = target.GetPixel(x, y);
                        int   r = c.R;
                        int   g = c.G;
                        int   b = c.B;
                        ++yValue1[r];
                        ++yValue1[g];
                        ++yValue1[b];
                    }
                }
                // 將點個數轉換為頻率
                total = w * h * 3;
                for (int i = 0; i < 256; ++i)
                {
                    yValue1[i] /= total;
                }
                // 設定x軸區間
                chart4.ChartAreas["ChartArea1"].AxisX.Interval = 32;
                // Intensities - 強度
                chart4.Series.Add("Intensities"); // 資料序列集合
                chart4.Series["Intensities"].ChartType = SeriesChartType.Column;
                chart4.Series["Intensities"].Points.DataBindXY(xValue, yValue1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }