Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Bitmap bmpAsli, bmpHasil;
- private void assignMatrix(int i, int j, ref byte[] red, ref byte[] green, ref byte[] blue)
- {
- int hi = i - 1;
- int hj = j - 1;
- for (int index = 0; index < 9; index++)
- {
- red[index] = bmpAsli.GetPixel(hi, hj).R;
- green[index] = bmpAsli.GetPixel(hi, hj).G;
- blue[index] = bmpAsli.GetPixel(hi, hj).R;
- if (hj - (j - 1) == 2)
- {
- hi += 1;
- hj = j - 1;
- }
- else
- {
- hj += 1;
- }
- }
- }
- private void sortMatrix(int size, ref byte[] red, ref byte[] green, ref byte[] blue)
- {
- for (int m = 0; m < size - 1; m++)
- {
- for (int n = 0; n < size - 1 - m; n++)
- {
- if (red[n] > red[n + 1])
- {
- byte temp = red[n];
- red[n] = red[n + 1];
- red[n + 1] = temp;
- }
- if (green[n] > green[n + 1])
- {
- byte temp = green[n];
- green[n] = green[n + 1];
- green[n + 1] = temp;
- }
- if (blue[n] > blue[n + 1])
- {
- byte temp = blue[n];
- blue[n] = blue[n + 1];
- blue[n + 1] = temp;
- }
- }
- }
- }
- private void buttonMedianFilter_Click(object sender, EventArgs e)
- {
- Cursor = Cursors.WaitCursor;
- byte[] red = new byte[9];
- byte[] green = new byte[9];
- byte[] blue = new byte[9];
- bmpAsli = (Bitmap)pictureBoxInput.Image;
- int nWidth = bmpAsli.Width - 1;
- int nHeight = bmpAsli.Height - 1;
- bmpHasil = new Bitmap(bmpAsli.Width, bmpAsli.Height);
- for (int i = 1; i < nWidth; i++)
- {
- for (int j = 1; j < nHeight; j++)
- {
- assignMatrix(i, j, ref red, ref green, ref blue);
- sortMatrix(9, ref red, ref green, ref blue);
- bmpHasil.SetPixel(i, j, Color.FromArgb(red[4], green[4], blue[4]));
- }
- }
- pictureBoxOutput.Image = bmpHasil;
- Cursor = Cursors.Default;
- }
- private void buttonMaxFilter_Click(object sender, EventArgs e)
- {
- Cursor = Cursors.WaitCursor;
- byte[] red = new byte[9];
- byte[] green = new byte[9];
- byte[] blue = new byte[9];
- bmpAsli = (Bitmap)pictureBoxInput.Image;
- int nWidth = bmpAsli.Width - 1;
- int nHeight = bmpAsli.Height - 1;
- bmpHasil = new Bitmap(bmpAsli.Width, bmpAsli.Height);
- for (int i = 1; i < nWidth; i++)
- {
- for (int j = 1; j < nHeight; j++)
- {
- assignMatrix(i, j, ref red, ref green, ref blue);
- sortMatrix(9, ref red, ref green, ref blue);
- bmpHasil.SetPixel(i, j, Color.FromArgb(red[8], green[8], blue[8]));
- }
- }
- pictureBoxOutput.Image = bmpHasil;
- Cursor = Cursors.Default;
- }
- private void buttonMinFilter_Click(object sender, EventArgs e)
- {
- Cursor = Cursors.WaitCursor;
- byte[] red = new byte[9];
- byte[] green = new byte[9];
- byte[] blue = new byte[9];
- bmpAsli = (Bitmap)pictureBoxInput.Image;
- int nWidth = bmpAsli.Width - 1;
- int nHeight = bmpAsli.Height - 1;
- bmpHasil = new Bitmap(bmpAsli.Width, bmpAsli.Height);
- for (int i = 1; i < nWidth; i++)
- {
- for (int j = 1; j < nHeight; j++)
- {
- assignMatrix(i, j, ref red, ref green, ref blue);
- sortMatrix(9, ref red, ref green, ref blue);
- bmpHasil.SetPixel(i, j, Color.FromArgb(red[0], green[0], blue[0]));
- }
- }
- pictureBoxOutput.Image = bmpHasil;
- Cursor = Cursors.Default;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement