예제 #1
0
        private void equalizationHistogramToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (pbInput.Image == null)
            {
                MessageBox.Show("Error!! Empty Input Image");
            }
            else
            {
                Dictionary <byte, double> histoR = new Dictionary <byte, double>();
                Dictionary <byte, double> histoG = new Dictionary <byte, double>();
                Dictionary <byte, double> histoB = new Dictionary <byte, double>();
                Bitmap image1 = new Bitmap(pbInput.Image);
                pbOutput.Image = image1;
                int         baris, kolom;
                CHistogram  frm3 = new CHistogram();  //RGB
                GSHistogram frm2 = new GSHistogram(); //Grayscale
                byte        c1, c2, c3;
                double[]    s1  = new double[256];
                double[]    s2  = new double[256];
                double[]    s3  = new double[256];
                double      jum = 0;
                //Proses inisiasi nilai awal histogram
                for (int counter = 0; counter <= 255; counter++)
                {
                    histoR[(Byte)counter] = 0.0;
                    histoG[(Byte)counter] = 0.0;
                    histoB[(Byte)counter] = 0.0;
                }
                // Proses mendapatkan nilai histogram
                for (baris = 0; baris < image1.Width; baris++)
                {
                    for (kolom = 0; kolom < image1.Height; kolom++)
                    {
                        c1 = image1.GetPixel(baris, kolom).R;
                        c2 = image1.GetPixel(baris, kolom).G;
                        c3 = image1.GetPixel(baris, kolom).B;
                        if (histoR.ContainsKey(c1))
                        {
                            histoR[c1] += 1;
                        }
                        if (histoG.ContainsKey(c2))
                        {
                            histoG[c2] += 1;
                        }
                        if (histoB.ContainsKey(c3))
                        {
                            histoB[c3] += 1; //kerja histogram
                        }
                    }
                }

                //Proses menghitung nilai transform function,
                List <byte> kunci1 = histoR.Keys.ToList();
                List <byte> kunci2 = histoG.Keys.ToList();
                List <byte> kunci3 = histoB.Keys.ToList();
                foreach (byte key in kunci1)
                {
                    histoR[key] = histoR[key] / (image1.Width * image1.Height);
                    jum        += 255 * histoR[key];
                    s1[key]     = jum;
                }
                jum = 0;

                foreach (byte key in kunci2)
                {
                    histoG[key] = histoG[key] / (image1.Width * image1.Height);
                    jum        += 255 * histoG[key];
                    s2[key]     = jum;
                }
                jum = 0;
                foreach (byte key in kunci3)
                {
                    histoB[key] = histoB[key] / (image1.Width * image1.Height);
                    jum        += 255 * histoB[key];
                    s3[key]     = jum;
                }
                progressBar1.Show();
                //Proses mengubah nilai pixel ke nilai baru sesuai transform function
                for (baris = 0; baris < image1.Width; baris++)
                {
                    for (kolom = 0; kolom < image1.Height; kolom++)
                    {
                        c1 = image1.GetPixel(baris, kolom).R;
                        c2 = image1.GetPixel(baris, kolom).G;
                        c3 = image1.GetPixel(baris, kolom).B;
                        int s   = Convert.ToInt16(s1[c1]);
                        int ss  = Convert.ToInt16(s2[c2]);
                        int sss = Convert.ToInt16(s3[c3]);
                        image1.SetPixel(baris, kolom, Color.FromArgb(s, ss, sss));
                    }
                    progressBar1.Value = Convert.ToInt32(Math.Floor((double)(100 * (baris + 1) /
                                                                             image1.Width)));
                }
                progressBar1.Hide();
                pbOutput.Refresh();
            }
        }
예제 #2
0
        private void outputToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (pbOutput.Image == null)
            {
                MessageBox.Show("Tidak ada citra yang akan diolah");
            }
            else
            {
                Dictionary <int, double> HistoR = new Dictionary <int, double>();
                Dictionary <int, double> HistoG = new Dictionary <int, double>();
                Dictionary <int, double> HistoB = new Dictionary <int, double>();

                Bitmap      b    = new Bitmap((Bitmap)this.pbOutput.Image);
                GSHistogram frm7 = new GSHistogram();
                CHistogram  frm8 = new CHistogram();

                for (int h = 0; h <= 255; h++)
                {
                    HistoR.Add(h, 0);
                    HistoG.Add(h, 0);
                    HistoB.Add(h, 0);
                }
                for (int i = 0; i < b.Width; i++)
                {
                    for (int j = 0; j < b.Height; j++)
                    {
                        Color c1 = b.GetPixel(i, j); //jika pada baris i kolom j, pixel bernilai n, maka nilai n pada dictionary ditambah 1

                        for (int k = 0; k <= 255; k++)
                        {
                            if (c1.G == k)
                            {
                                HistoG[k] = HistoG[k] + 1;
                            }
                            if (c1.R == k)
                            {
                                HistoR[k] = HistoR[k] + 1;
                            }
                            if (c1.B == k)
                            {
                                HistoB[k] = HistoB[k] + 1;
                            }
                        }
                    }
                    progressBar1.Value = Convert.ToInt16(100 * (i + 1) / b.Width);
                }
                progressBar1.Visible = false;
                frm7.chartGSHistogram.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
                frm7.chartGSHistogram.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled = false;

                frm8.chartR.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
                frm8.chartR.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled = false;
                frm8.chartG.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
                frm8.chartG.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled = false;
                frm8.chartB.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
                frm8.chartB.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled = false;

                if (HistoR.Count == HistoG.Count && !HistoR.Except(HistoG).Any())
                {
                    frm7.chartGSHistogram.Series["Series1"].Color = Color.Gray;
                    frm7.chartGSHistogram.Series[0].Points.DataBindXY(HistoR.Keys, HistoR.Values);
                    frm7.ShowDialog();
                }
                else
                {
                    frm8.chartR.Series["Series1"].Color = Color.Red;
                    frm8.chartG.Series["Series1"].Color = Color.Green;
                    frm8.chartB.Series["Series1"].Color = Color.Blue;

                    frm8.chartR.Series[0].Points.DataBindXY(HistoR.Keys, HistoR.Values);
                    frm8.chartG.Series[0].Points.DataBindXY(HistoG.Keys, HistoG.Values);
                    frm8.chartB.Series[0].Points.DataBindXY(HistoB.Keys, HistoB.Values);
                    frm8.ShowDialog();
                }
            }
        }