图片去干扰

dolo1984 2014-02-10 05:27:10

图片已经二值化了,但是怎么去掉上面的干扰线呢?求大神指点。。
...全文
307 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
md5e 2014-02-11
  • 打赏
  • 举报
回复
发原图片地址过来看看
dolo1984 2014-02-11
  • 打赏
  • 举报
回复
引用 3 楼 liuchaolin 的回复:
将二值化的比利设置大点试试
大点好像不启作用,这些干扰还是有。
md5e 2014-02-11
  • 打赏
  • 举报
回复
将二值化的比利设置大点试试
dolo1984 2014-02-11
  • 打赏
  • 举报
回复
引用 1 楼 BenBenBears 的回复:
http://www.cnblogs.com/yuanbao/archive/2007/11/14/958488.html
这个不起效果,用了中值后,图片变得没法看。
md5e 2014-02-11
  • 打赏
  • 举报
回复
Bitmap sourcebm = new Bitmap("1392096751_635541.jpg");
setcolor(sourcebm);
clearcolor(sourcebm);

private void setcolor(Bitmap sourcebm)
{
int w = 160;
for (int x = 0; x < sourcebm.Width; x++)
{
for (int y = 0; y < sourcebm.Height; y++)
{
Color c = sourcebm.GetPixel(x, y);
if (c.R > w && c.G > w && c.B > w)
{
sourcebm.SetPixel(x, y, Color.FromArgb(0, 0, 0));
}
else
{
sourcebm.SetPixel(x, y, Color.FromArgb(255, 255, 255));
}
}
}
}
private void clearcolor(Bitmap sourcebm)
{
for (int x = 0; x < sourcebm.Width; x++)
{
for (int y = 0; y < sourcebm.Height; y++)
{
Color c = sourcebm.GetPixel(x, y);
if (c.R == 0)
{
//去掉竖线
#region 去掉竖线
List<Point> _list = new List<Point>();
for (int _y = y; _y < sourcebm.Height; _y++)
{
Color _c = sourcebm.GetPixel(x, _y);
if (_c.R != 0)
{
break;
}
Point pl = new Point(x - 1 >= 0 ? (x - 1) : (x + 2), _y);
Point pr = new Point(x + 1 < sourcebm.Width ? (x + 1) : (x - 2), _y);

if (sourcebm.GetPixel(pl.X, pl.Y).R != 0 && sourcebm.GetPixel(pr.X, pr.Y).R != 0)
{
_list.Add(new Point(x, _y));
}
else
{
break;
}
}
if (_list.Count > 1)
{
for (int i = 0; i < _list.Count; i++)
{
sourcebm.SetPixel(_list[i].X, _list[i].Y, Color.FromArgb(255, 255, 255));
}
}
#endregion

//去掉斜线
#region 去掉斜线
_list.Clear();
int _x = x;
for (int _y = y; _y < sourcebm.Height && _x < sourcebm.Width; _y++)
{
Color _c = sourcebm.GetPixel(_x, _y);
if (_c.R != 0)
{
break;
}
Point pl = new Point(_x - 1 >= 0 ? (_x - 1) : (_x + 2), _y);
Point pr = new Point(_x + 1 < sourcebm.Width ? (_x + 1) : (_x - 2), _y);
Point pt = new Point(_x, _y - 1 >= 0 ? (_y - 1) : _y + 2);
Point pd = new Point(_x, _y + 1 < sourcebm.Height ? (_y + 1) : (_y - 2));
if ((sourcebm.GetPixel(pl.X, pl.Y).R != 0 && sourcebm.GetPixel(pr.X, pr.Y).R != 0) || (sourcebm.GetPixel(pt.X, pt.Y).R != 0 && sourcebm.GetPixel(pd.X, pd.Y).R != 0))
{
_list.Add(new Point(_x, _y));
}
else
{
break;
}
_x++;
}
if (_list.Count > 1)
{
for (int i = 0; i < _list.Count; i++)
{
sourcebm.SetPixel(_list[i].X, _list[i].Y, Color.FromArgb(255, 255, 255));
}
}
#endregion
}
}
}
}

也只能是这个效果了
dolo1984 2014-02-11
  • 打赏
  • 举报
回复
引用 5 楼 liuchaolin 的回复:
发原图片地址过来看看

怎么不显示呢?
dolo1984 2014-02-11
  • 打赏
  • 举报
回复
引用 5 楼 liuchaolin 的回复:
发原图片地址过来看看

这是源图片。

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧