public void Philter(Philter_matrix p_m) { Transp(ref p_m.matrix); int matrix_size = (int)Math.Sqrt(p_m.matrix.Length); int d_m = (int)Math.Floor((double)matrix_size / 2); ColorSpace[] new_pict = new ColorSpace[width * height]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { double a = 0, b = 0, c = 0; for (int k2 = -d_m; k2 < matrix_size - d_m; k2++) { for (int k1 = -d_m; k1 < matrix_size - d_m; k1++) { int iter = i + 1 * k2 + (j + 1 * k1) * width; if (iter >= 0 && iter < width * height) { a += (double)byte_picture[iter].a * p_m.matrix[k2 + d_m, k1 + d_m]; b += (double)byte_picture[iter].b * p_m.matrix[k2 + d_m, k1 + d_m]; c += (double)byte_picture[iter].c * p_m.matrix[k2 + d_m, k1 + d_m]; } } } a = a * p_m.mult + p_m.summ; b = b * p_m.mult + p_m.summ; c = c * p_m.mult + p_m.summ; a = a < 0 ? 0 : a; b = b < 0 ? 0 : b; c = c < 0 ? 0 : c; a = a > 255 ? 255 : a; b = b > 255 ? 255 : b; c = c > 255 ? 255 : c; new_pict[i + j * width].a = (byte)Math.Round(a); if (p_m.grey) { new_pict[i + j * width].b = new_pict[i + j * width].c = new_pict[i + j * width].a; } else { new_pict[i + j * width].b = (byte)Math.Round(b); new_pict[i + j * width].c = (byte)Math.Round(c); } } } byte_picture = new_pict; }
//sharpness private void sharpnessToolStripMenuItem_Click(object sender, EventArgs e) { double[,] RAZGLAD = { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } }; Philter_matrix razglad = new Philter_matrix(RAZGLAD); img_loader.Philter(razglad); pictureBox1.Image = img_loader.Razconvert(img_loader.get_byte); CreateClone(); }
//blur private void blurToolStripMenuItem_Click(object sender, EventArgs e) { double[,] ZGLAD = { { 1, 2, 1 }, { 2, 5, 2 }, { 1, 2, 1 } }; Philter_matrix zglad = new Philter_matrix(ZGLAD, 1.0 / 16); img_loader.Philter(zglad); pictureBox1.Image = img_loader.Razconvert(img_loader.get_byte); CreateClone(); }
//relief_beta private void greyContursToolStripMenuItem_Click(object sender, EventArgs e) { double[,] RELIEF2 = { { -1, -1, -1 }, { -1, 8, -1 }, { -1, -1, -1 } }; Philter_matrix relief2 = new Philter_matrix(RELIEF2, 1, 128, true); img_loader.Philter(relief2); pictureBox1.Image = img_loader.Razconvert(img_loader.get_byte); CreateClone(); }
//relief_alpha private void reliefToolStripMenuItem_Click(object sender, EventArgs e) { double[,] RELIEF1 = { { 0, 0, -1 }, { 0, 0, 0 }, { 1, 0, 0 } }; Philter_matrix relief1 = new Philter_matrix(RELIEF1, 1, 128, true); img_loader.Philter(relief1); pictureBox1.Image = img_loader.Razconvert(img_loader.get_byte); CreateClone(); }