首页 > 代码库 > 边缘探测
边缘探测
Color C1, C2, C3, C4; int r1, r2, r3, r4, g1, g2, g3, g4, b1, b2, b3, b4, rx, ry, gx, gy, bx, by, rr, gg, bb; Bitmap bmp = new Bitmap(pictureBox1.Image); Bitmap tmp = (Bitmap)bmp.Clone(); for (int i = 0; i < bmp.Width - 1; i++) for (int j = 0; j < bmp.Height - 1; j++) { //获得相邻4个像素颜色值 ///斜对角 C1 = bmp.GetPixel(i, j); C2 = bmp.GetPixel(i + 1, j + 1); C3 = bmp.GetPixel(i + 1, j); C4 = bmp.GetPixel(i, j + 1); //红色分量值 r1 = C1.R; r2 = C2.R; r3 = C3.R; r4 = C4.R; rx = r1 - r2; ry = r3 - r4; rr = Math.Abs(rx) + Math.Abs(ry) + 128; //绿色分量值 g1 = C1.G; g2 = C2.G; g3 = C3.G; g4 = C4.G; gx = g1 - g2; gy = g3 - g4; gg = Math.Abs(gx) + Math.Abs(gy) + 128; //蓝色分量值 b1 = C1.B; b2 = C2.B; b3 = C3.B; b4 = C4.B; bx = b1 - b2; by = b3 - b4; bb = Math.Abs(bx) + Math.Abs(by) + 128; //处理颜色值溢出 rr = rr > 255 ? 255 : rr; rr = rr < 0 ? 0 : rr; gg = gg > 255 ? 255 : gg; gg = gg < 0 ? 0 : gg; bb = bb > 255 ? 255 : bb; bb = bb < 0 ? 0 : bb; tmp.SetPixel(i, j, Color.FromArgb(rr, gg, bb)); } pictureBox2.Image = tmp;
边缘探测
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。