/// <summary> /// /// </summary> /// <param name="file_name"> </param> private ImageMatrix crate_matrix(string file_name) { Bitmap picture = new Bitmap(file_name); ImageMatrix res = new ImageMatrix(); using (var wrapper = new ImageWrapper(picture,true)) { res.matrix = new int[wrapper.Width, wrapper.Height]; for (int i = 0; i < wrapper.Width; i++) { for (int j = 0; j < wrapper.Height; j++) { Color color = wrapper[i, j]; res.matrix[i, j] = (color.R + color.G + color.B) / 3; } } res.height = wrapper.Height; res.width = wrapper.Width; res.picture = picture; } return res; } private void tsmiDifference_Click(object sender, EventArgs e) { ImageMatrix matrix1 = crate_matrix("D:\\3\\1.png"); ImageMatrix matrix2 = crate_matrix("D:\\3\\2.png"); Bitmap picture = new Bitmap(matrix1.picture); using (var wrapper = new ImageWrapper(picture, true)) { for (int i = 0; i < wrapper.Width; i++) { for (int j = 1; j < wrapper.Height; j++) { int light1 = matrix1.matrix[i, j]; int light2 = matrix2.matrix[i, j]; int light = Math.Abs(light2-light1); wrapper[i, j] = Color.FromArgb(light, light, light); } } pbImage.Image = picture; } }
Source: https://habr.com/ru/post/268445/
All Articles