Modul 4 Pengelolaan Citra Digital
Modul 4 Pengelolaan Citra Digital
ALFIAN KURNIAWAN
1741727011
TI-4H
b.SetPixel(i, j,
Color.FromArgb(paletteColor[Convert.ToInt16(baru), 0],
paletteColor[Convert.ToInt16(baru), 1], paletteColor[Convert.ToInt16(baru), 2]));
errorR = merah - b.GetPixel(i, j).R;
errorG = hijau - b.GetPixel(i, j).G;
errorB = biru - b.GetPixel(i, j).B;
b.SetPixel(i + 1, j,
Color.FromArgb((int)truncate2(b.GetPixel(i + 1, j).R + ((7.0 / 16.0) * errorR)),
(int)truncate2(b.GetPixel(i + 1, j).G + ((7.0 / 16.0) * errorG)),
(int)truncate2(b.GetPixel(i + 1, j).B + ((7.0 / 16.0) * errorB))));
if (i > 0)
{
b.SetPixel(i - 1, j + 1,
Color.FromArgb((int)truncate2(b.GetPixel(i - 1, j + 1).R + ((3.0 / 16.0) * errorR)),
(int)truncate2(b.GetPixel(i - 1, j + 1).G + ((3.0 / 16.0) * errorG)),
(int)truncate2(b.GetPixel(i - 1, j + 1).B + ((3.0 / 16.0) * errorB))));
}
b.SetPixel(i, j + 1,
Color.FromArgb((int)truncate2(b.GetPixel(i, j + 1).R + ((5.0 / 16.0) * errorR)),
(int)truncate2(b.GetPixel(i, j + 1).G + ((5.0 / 16.0) * errorG)),
(int)truncate2(b.GetPixel(i, j + 1).B + ((5.0 / 16.0) * errorB))));
b.SetPixel(i + 1, j + 1,
Color.FromArgb((int)truncate2(b.GetPixel(i + 1, j + 1).R + ((1.0 / 16.0) * errorR)),
(int)truncate2(b.GetPixel(i + 1, j + 1).G + ((1.0 / 16.0) * errorG)),
(int)truncate2(b.GetPixel(i + 1, j + 1).B + ((1.0 / 16.0) * errorB))));
}
ProgressBar1.Value = Convert.ToInt16(100 * (i + 1) / b.Width);
}
ProgressBar1.Visible = false;
this.pictureBox2.Refresh();
}
}
b. Hasil :
2. Histogram
a. Kode program :
private void inputToolStripMenuItem_Click(object sender, EventArgs e)
{
{
if (pictureBox1.Image == null)
{
MessageBox.Show("None");
}
else
{
double[] HistoR = new double[256];
double[] HistoG = new double[256];
double[] HistoB = new double[256];
Bitmap b = new Bitmap((Bitmap)this.pictureBox1.Image);
Form8 frm8 = new Form8();
Form7 frm7 = new Form7();
for (int i = 0; i < 255; i++)
{
HistoR[i] = 0;
HistoG[i] = 0;
HistoB[i] = 0;
}
for (int i = 0; i <= 255; i++)
{
for (int j = 0; j <= 255; j++)
{
Color c1 = b.GetPixel(i, j);
int merah = c1.R;
int hijau = c1.G;
int biru = c1.B;
HistoR[merah]++;
HistoG[hijau]++;
HistoB[biru]++;
}
ProgressBar1.Value = Convert.ToInt16(100 * (i + 1) /
b.Width);
}
ProgressBar1.Visible = false;
Double sumR = 0;
for (int i = 0; i < 255; i++)
{
if (HistoG[i] == HistoB[i])
{
sumR++;
}
}
if (sumR == 255)
{
frm7.chart1.Series["Series1"].Color = Color.Gray;
frm7.chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled
= false;
frm7.chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled
= false;
frm8.chart2.Series["Series1"].Color = Color.Green;
frm8.chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled
= false;
frm8.chart2.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled
= false;
frm8.chart3.Series["Series1"].Color = Color.Blue;
frm8.chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled
= false;
frm8.chart3.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled
= false;
}
}
b. Hasil :