Exemplo n.º 1
0
        // 載入底圖
        private void button1_Click(object sender, EventArgs e)
        {
            // 設為初始值
            pictureBox2.Image = null;
            trackBar1.Value   = 0;
            textBox1.Text     = "0";
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "開啟圖檔";
            openFileDialog.Filter = "pcx files (*.pcx)|*.pcx";
            if (openFileDialog.ShowDialog() == DialogResult.OK && openFileDialog.FileName.Length > 0)
            {
                pcxBase           = new ImgPcx(openFileDialog.FileName);
                pictureBox2.Image = pcxBase.pcxImg;
                // 載入底圖後, 開放使用工具
                trackBar1.Enabled = true;
                textBox1.Enabled  = true;
            }
            else
            {
                // 載入底圖失敗, 無法使用工具
                trackBar1.Enabled = false;
                textBox1.Enabled  = false;
            }
        }
Exemplo n.º 2
0
        // 數值變動時
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int value;

            if (int.TryParse(textBox1.Text, out value))
            {
                if (value > 255)
                {
                    textBox1.Text = "255";
                    value         = 255;
                }
                else if (value < 0)
                {
                    textBox1.Text = "0";
                    value         = 0;
                }

                trackBar1.Value = value;
                pcxAfter        = new ImgPcx(pcxGray);
                pcxAfter.Threshold(value);
                pictureBox2.Image = pcxAfter.pcxImg;
                // 顯示SNR值 (到小數後2位)
                textBox2.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
            }
        }
Exemplo n.º 3
0
 // Gray Code
 private void button2_Click(object sender, EventArgs e)
 {
     if (markFlag)
     {
         // 還原
         pcxGray = new ImgPcx(pcxBackup);
         // 浮水印處理
         pcxGray.Watermark(pcxMark, "Gray");
         pictureBox10.Image = pcxGray.pcxImg;
         label1.Text        = "Original Image";
         label2.Text        = "WaterMark Inserted";
         // 顯示SNR值 (到小數後2位)
         label3.Visible   = true;
         textBox1.Visible = true;
         textBox1.Text    = pcxBackup.GetSNR(pcxBackup, pcxGray).ToString("f2");
     }
     pictureBox1.Image = pcxGray.BitPlane(128, "Gray");
     pictureBox2.Image = pcxGray.BitPlane(64, "Gray");
     pictureBox3.Image = pcxGray.BitPlane(32, "Gray");
     pictureBox4.Image = pcxGray.BitPlane(16, "Gray");
     pictureBox5.Image = pcxGray.BitPlane(8, "Gray");
     pictureBox6.Image = pcxGray.BitPlane(4, "Gray");
     pictureBox7.Image = pcxGray.BitPlane(2, "Gray");
     pictureBox8.Image = pcxGray.BitPlane(1, "Gray");
 }
Exemplo n.º 4
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.º 5
0
 // 縮小(線性插值)
 private void button4_Click(object sender, EventArgs e)
 {
     pcxAfter = new ImgPcx(pcxOrigin);
     pcxAfter.ZoomOut_Interpolation(Double.Parse(textBox1.Text));
     pictureBox1.Image = pcxAfter.pcxImg;
     // 顯示SNR值 (到小數後2位)
     textBox2.Text = pcxOrigin.GetSNR(pcxAfter, pcxOrigin).ToString("f2");
 }
Exemplo n.º 6
0
 private void numericUpDown1_ValueChanged(object sender, EventArgs e)
 {
     pcxAfter = new ImgPcx(pcxGray);
     pcxAfter.HighBoost((double)numericUpDown1.Value);
     pictureBox2.Image = pcxAfter.pcxImg;
     // 顯示SNR值 (到小數後2位)
     textBox1.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
 }
Exemplo n.º 7
0
 private void FormHighpass_Load(object sender, EventArgs e)
 {
     pictureBox1.Image = pcxGray.pcxImg;
     pcxAfter          = new ImgPcx(pcxGray);
     pcxAfter.Highpass();
     pictureBox2.Image = pcxAfter.pcxImg;
     // 顯示SNR值 (到小數後2位)
     textBox1.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
 }
Exemplo n.º 8
0
 // 反旋轉
 private void radioButton2_CheckedChanged(object sender, EventArgs e)
 {
     if (radioButton2.Checked == true)
     {
         pcxAfter = new ImgPcx(pcxOrigin);
         // double.Parse() : 字串轉為double
         pcxAfter.RotateBackward(double.Parse(textBox1.Text));
         pictureBox1.Image = pcxAfter.pcxImg;
     }
 }
Exemplo n.º 9
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.º 10
0
 private void FormBitPlane_Load(object sender, EventArgs e)
 {
     // 顯示原始灰階圖
     pictureBox9.Image = pcxGray.pcxImg;
     // 備份
     pcxBackup = new ImgPcx(pcxGray);
     // 隱藏SNR
     label3.Visible   = false;
     textBox1.Visible = false;
 }
Exemplo n.º 11
0
 // 兩者
 private void radioButton3_CheckedChanged(object sender, EventArgs e)
 {
     if (radioButton3.Checked == true)
     {
         pcxAfter = new ImgPcx(pcxGray);
         pcxAfter.Roberts("both");
         pictureBox2.Image = pcxAfter.pcxImg;
         // 顯示SNR值 (到小數後2位)
         textBox1.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
     }
 }
Exemplo n.º 12
0
        // 移動拉桿時
        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            int value = trackBar1.Value;
            // 轉成百分比
            float percentage = (float)(value / 100.0);

            textBox1.Text = percentage.ToString();
            pcxAfter      = new ImgPcx(pcxBase);
            pcxAfter.Transparency(pcxOrigin, percentage);
            pictureBox2.Image = pcxAfter.pcxImg;
        }
Exemplo n.º 13
0
        // 計算Otsu's thresholding
        private void btnOtsu_Click(object sender, EventArgs e)
        {
            pcxAfter = new ImgPcx(pcxGray);
            // Otsu's threshold值
            int threshold = pcxAfter.OtsuThreshold();

            trackBar1.Value   = threshold;
            textBox1.Text     = threshold.ToString();
            pictureBox2.Image = pcxAfter.pcxImg;
            // 顯示SNR值 (到小數後2位)
            textBox2.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
        }
Exemplo n.º 14
0
 private void radioButton2_CheckedChanged(object sender, EventArgs e)
 {
     if (radioButton2.Checked == true)
     {
         textBox1.Text = mask2;
         pcxAfter      = new ImgPcx(pcxGray);
         pcxAfter.EdgeCrispening("mask2");
         pictureBox2.Image = pcxAfter.pcxImg;
         // 顯示SNR值 (到小數後2位)
         textBox2.Text = pcxGray.GetSNR(pcxGray, pcxAfter).ToString("f2");
     }
 }
Exemplo n.º 15
0
        private void FormComponent_Load(object sender, EventArgs e)
        {
            // 先將原圖用Otsu's threshold處理成二值圖
            pcxBinary = new ImgPcx(pcxGray);
            // Otsu's threshold值
            int threshold = pcxBinary.OtsuThreshold();

            pictureBox1.Image = pcxBinary.pcxImg;

            // Connected Component Analysis
            label2.Text      += pcxBinary.Component();
            pictureBox2.Image = pcxBinary.pcxImg;
        }
Exemplo n.º 16
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.º 17
0
        // 加入浮水印
        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "開啟圖檔";
            openFileDialog.Filter = "pcx files (*.pcx)|*.pcx";
            if (openFileDialog.ShowDialog() == DialogResult.OK && openFileDialog.FileName.Length > 0)
            {
                pcxMark = new ImgPcx(openFileDialog.FileName);
                // 浮水印轉灰階
                pcxMark.Gray();
                pictureBox1.Image = null;
                pictureBox2.Image = null;
                pictureBox3.Image = null;
                pictureBox4.Image = null;
                pictureBox5.Image = null;
                pictureBox6.Image = null;
                pictureBox7.Image = null;
                pictureBox8.Image = null;
                markFlag          = true;
            }
            else
            {
                // 還原
                pcxGray            = new ImgPcx(pcxBackup);
                markFlag           = false;
                pictureBox1.Image  = null;
                pictureBox2.Image  = null;
                pictureBox3.Image  = null;
                pictureBox4.Image  = null;
                pictureBox5.Image  = null;
                pictureBox6.Image  = null;
                pictureBox7.Image  = null;
                pictureBox8.Image  = null;
                pictureBox10.Image = null;
                label1.Text        = "";
                label2.Text        = "";
                // 隱藏SNR
                label3.Visible   = false;
                textBox1.Visible = false;
            }
        }
Exemplo n.º 18
0
        // 旋轉角度拉條
        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            int value = trackBar1.Value;

            textBox1.Text = value.ToString();
            if (radioButton1.Checked == true)
            {
                pcxAfter = new ImgPcx(pcxOrigin);
                // double.Parse() : 字串轉為double
                pcxAfter.RotateForward(value);
                pictureBox1.Image = pcxAfter.pcxImg;
            }
            else if (radioButton2.Checked == true)
            {
                pcxAfter = new ImgPcx(pcxOrigin);
                // double.Parse() : 字串轉為double
                pcxAfter.RotateBackward(value);
                pictureBox1.Image = pcxAfter.pcxImg;
            }
        }
Exemplo n.º 19
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;

                // 灰階
                pictureBox3.Image = pcxGray.pcxImg;
                pcxAfter          = new ImgPcx(pcxGray);
                // 負片
                pcxAfter.Invert();
                pictureBox4.Image = pcxAfter.pcxImg;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 20
0
        // 數值變動時
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            float value;

            if (float.TryParse(textBox1.Text, out value))
            {
                if (value > 1)
                {
                    textBox1.Text = "1";
                    value         = 1;
                }
                else if (value < 0)
                {
                    textBox1.Text = "0";
                    value         = 0;
                }

                // 百分比轉成數值, trackBar只能用整數
                trackBar1.Value = (int)(value * 100);
                pcxAfter        = new ImgPcx(pcxBase);
                pcxAfter.Transparency(pcxOrigin, value);
                pictureBox2.Image = pcxAfter.pcxImg;
            }
        }
Exemplo n.º 21
0
 // 垂直翻轉
 private void button2_Click(object sender, EventArgs e)
 {
     pcxAfter = new ImgPcx(pcxOrigin);
     pcxAfter.UpSideDown();
     pictureBox2.Image = pcxAfter.pcxImg;
 }
Exemplo n.º 22
0
        // 讀檔
        private void menuOpen_Click(object sender, EventArgs e)
        {
            try
            {
                // 清空顯示圖片與資訊
                pictureBox1.Image     = null;
                pictureBox2.Image     = null;
                pictureBox3.Image     = null;
                dataGridView1.Visible = false;
                labelXY.Text          = "";
                labelR.Text           = "";
                labelG.Text           = "";
                labelB.Text           = "";
                labelDim.Text         = "";
                chart1.Visible        = false;

                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Title  = "開啟圖檔";
                openFileDialog.Filter = "pcx files (*.pcx)|*.pcx";
                if (openFileDialog.ShowDialog() == DialogResult.OK && openFileDialog.FileName.Length > 0)
                {
                    pcxOrigin = new ImgPcx(openFileDialog.FileName);

                    // test Save()
                    //pcx.Save("Sample_save");

                    // 將載入的圖像放到pictureBox1
                    pictureBox1.Image = pcxOrigin.pcxImg;
                    // 顯示圖像header資訊
                    string[,] info = pcxOrigin.GetInfo();
                    for (int i = 0; i < 16; ++i)
                    {
                        dataGridView1.Rows.Add(new object[] { info[i, 0], info[i, 1] });
                    }
                    dataGridView1.Visible = true;
                    // nPlanes = 3, 無調色盤
                    if (pcxOrigin.head.nPlanes == 1)
                    {
                        // 畫出調色盤
                        var      colors    = pcxOrigin.pcxImg.Palette.Entries;  // 取得調色盤
                        int      cntColors = colors.Count();                    // 計算顏色總數 (ex: 256)
                        int      row       = cntColors / 16;                    // (ex: 256 / 16 = 16)
                        int      column    = cntColors / 16;                    // (ex: 256 / 16 = 16)
                        Bitmap   palette   = new Bitmap(row * 15, column * 15); // 建立調色盤圖像
                        Graphics g         = Graphics.FromImage(palette);       // 繪圖介面

                        /*
                         * @curX : 圖像x座標
                         * @curY : 圖像y座標
                         * @cnt  : 計算此列已畫好的顏色數 (用來判斷何時換行)
                         */
                        int curX = 0, curY = 0, cnt = 0;
                        for (int i = 0; i < cntColors; ++i)
                        {
                            // 挑出顏色給筆刷
                            SolidBrush brush = new SolidBrush(Color.FromArgb(colors[i].A, colors[i].R, colors[i].G, colors[i].B));
                            // 畫矩形
                            g.FillRectangle(brush, curX, curY, 15, 15);
                            ++cnt;
                            if (cnt == row) // 換行繼續畫
                            {
                                curX  = 0;
                                curY += 15;
                                cnt   = 0;
                            }
                            else           // 右移繼續畫
                            {
                                curX += 15;
                            }
                        }
                        // 顯示調色盤
                        pictureBox3.Image = palette;
                    }
                    // 顯示圖像長寬
                    labelDim.Text = pcxOrigin.head.width.ToString() + " x " + pcxOrigin.head.height.ToString();

                    // 開檔後, 開放使用存檔與工具
                    menuSave.Enabled   = true;
                    menuTool.Enabled   = true;
                    menuFilter.Enabled = true;
                    menuCoding.Enabled = true;

                    // 預先製作並保存灰階影像
                    pcxGray = new ImgPcx(pcxOrigin);
                    pcxGray.Gray();

                    // 清除圖表資料(可重複使用)
                    chart1.Series.Clear();

                    // 繪製histogram
                    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);
                    chart1.Visible           = true;
                }
                else
                {
                    // 開檔失敗, 無法使用存檔與工具
                    menuSave.Enabled   = false;
                    menuTool.Enabled   = false;
                    menuFilter.Enabled = false;
                    menuCoding.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 23
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);
            }
        }
Exemplo n.º 24
0
 private void FormMedian_Load(object sender, EventArgs e)
 {
     pictureBox1.Image = pcxGray.pcxImg;
     pcxAfter          = new ImgPcx(pcxGray);
 }
Exemplo n.º 25
0
        // 移動拉桿時
        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            int value = trackBar1.Value;

            textBox1.Text = value.ToString();
            pcxAfter      = new ImgPcx(pcxGray);
            pcxAfter.Threshold(value);
            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 = value;
            stripline.StripWidth     = 1;
            stripline.BackColor      = Color.Red;
            chart1.ChartAreas["ChartArea1"].AxisX.StripLines.Add(stripline);
        }
Exemplo n.º 26
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.º 27
0
 // 右斜翻轉
 private void button4_Click(object sender, EventArgs e)
 {
     pcxAfter = new ImgPcx(pcxOrigin);
     pcxAfter.RightDiagonal();
     pictureBox2.Image = pcxAfter.pcxImg;
 }
Exemplo n.º 28
0
 // 縮小(線性插值)
 private void button4_Click(object sender, EventArgs e)
 {
     pcxAfter = new ImgPcx(pcxOrigin);
     pcxAfter.ZoomOut_Interpolation(Double.Parse(textBox1.Text));
     pictureBox1.Image = pcxAfter.pcxImg;
 }