Beispiel #1
0
        private void HistRed_Click(object sender, EventArgs e)
        {
            int temp = 0, baris = 0, data = 0, data2 = 0, temp2 = 0, baris2 = 0;

            Histogram Hg = new Histogram();

            Bitmap citra = new Bitmap(original.Image);

            //int[] histo;
            //mendapat nilai tiap RGB

            int[] histogramRed = Hg.HistogramAngkaRed(citra);

            int[] histogramGreen = Hg.HistogramAngkaGreen(citra);

            int[] histogramBlue = Hg.HistogramAngkaBlue(citra);

            listBox1.Items.Clear();

            while (baris < histogramRed.Length)
            {

                temp = histogramRed[baris];

                if (data < temp)
                {

                    data = temp;

                }

                baris++;

            }

            int y = data / 250;

            for (int i = 0; i <= 255; i++)
            {

                listBox1.Items.Add(i + "=" + histogramRed[i]);

                Label lb = new Label();

                int x = Convert.ToInt32(histogramRed[i]);

                lb.Height = x / y;

                lb.Width = 1;

                lb.BackColor = Color.Red;

                //bkin label sbg grapik hist nya. edit posisinya nilainya saja

                //lb.Location = new Point(675 + i, 400 - lb.Height);
                lb.Location = new Point(876 + i, 331 - lb.Height);
                this.Controls.Add(lb);
                //panelHist.Controls.Add(lb);
                lb.ResetText();

            }

            int banyakPixel = citra.Width * citra.Height;

            byte[] hasilR = Hg.HasilHistEqArr(histogramRed, banyakPixel);

            byte[] hasilG = Hg.HasilHistEqArr(histogramGreen, banyakPixel);

            byte[] hasilB = Hg.HasilHistEqArr(histogramBlue, banyakPixel);

            listBox2.Items.Clear();

            //searching nilai tertinggi terlebih dahulu (sequential search)

            while (baris2 < hasilR.Length)
            {

                temp2 = hasilR[baris2];

                if (data2 < temp2)
                {

                    data2 = temp2;

                }

                baris2++;

            }

            //Execute2.Text = data2.ToString();

            int z = data2 / 250;

            for (int i = 0; i <= 255; i++)
            {

                listBox2.Items.Add(i + "=" + hasilR[i]);

                Label lb = new Label();

                int x = Convert.ToInt32(hasilR[i]);

                lb.Height = x / y;

                lb.Width = 1;

                lb.BackColor = Color.Red;

                //lb.Location = new Point(675 + i, 500 - lb.Height);
                lb.Location = new Point(877 + i, 430 - lb.Height);
                this.Controls.Add(lb);
                //panelHist.Controls.Add(lb);

            }

            Hg.HistogramBar(citra, hasilR, hasilG, hasilB);

            //Hg.HistogramBar(citra, HasilRGB(), HasilRGB(), HasilRGB());
            result.Image = citra;
        }