如何去除图像毛刺

weixin_44941424 2020-10-19 10:31:08
去除图像毛刺
...全文
2151 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
m.n.m 2021-07-12
  • 打赏
  • 举报
回复

你好,我最近也遇到了这个问题,不知道你是怎么解决的呢

luofeiju 2021-02-03
  • 打赏
  • 举报
回复
有两点信息可以利用: 1 记录主线条方向,在分叉点选择方向方向相对一致的点; 2 始终根据分叉后线条长度较长的线条,在分叉时同时跟踪两条(或多条)线条,当其中一条遇到终点而另一条仍然可继续跟踪,放弃遇到终点那条 以下代码使用了方向信息: void ExtractEdge(unsigned char* img, short width, short height, short channel, vector<vector<PairS>>& edge, int minLength) { if(!img || channel != 1 || width <= 0 || height <= 0) return; edge.clear(); short widthstep = (width + 3) / 4 * 4; memset(img, 0, widthstep); memset(img + widthstep * (height - 1), 0, widthstep); for(int y = 0; y < height; ++y) { *(img + y * widthstep) = 0; *(img + y * widthstep + width - 1) = 0; } for(short y = 1; y < height - 1; ++y) for(short x = 1; x < width - 1; ++x) { if(*(img + y * widthstep + x) > 0) { short cnts = 0; for(short yy = y - 1; yy <= y + 1; ++yy) { for(short xx = x - 1; xx <= x + 1; ++xx) { if(*(img + yy * widthstep + xx) > 0) ++cnts; } } // 找到线段端点 if(cnts == 2) { *(img + y * widthstep + x) = 0; vector<PairS> singleEdge; PairS pt(x, y); singleEdge.push_back(pt); // 寻找连续线段 while(1) { int cnts2 = 0; PairS pt2(0, 0); for(int yy = pt.y - 1; yy <= pt.y + 1; ++yy) for(int xx = pt.x - 1; xx <= pt.x + 1; ++xx) { if(*(img + yy * widthstep + xx) > 0) { pt2.x = xx; pt2.y = yy; ++cnts2; } } if(cnts2 <= 0) break; else if(cnts2 == 1) { *(img + pt2.y * widthstep + pt2.x) = 0; pt.x = pt2.x; pt.y = pt2.y; singleEdge.push_back(pt); } else { // 当存在多个点时,使用方向一致的的点 float dx = pt.x - singleEdge[0].x; float dy = pt.y - singleEdge[0].y; // 避免dx,dy均为零情形 if(dx == 0. && dy == 0.) { dx = 1; dy = 1; } float maxCosine = 0; PairS maxPos(0, 0); for(int yy = pt.y - 1; yy <= pt.y + 1; ++yy) for(int xx = pt.x - 1; xx <= pt.x + 1; ++xx) { if(*(img + yy * widthstep + xx) > 0) { float ddx = xx - pt.x; float ddy = yy - pt.y; float cs = (dx * ddx + dy * ddy) / (sqrt(dx * dx + dy * dy) * sqrt(ddx * ddx + ddy * ddy)); if(maxCosine <= abs(cs)) { maxCosine = abs(cs); maxPos.x = xx; maxPos.y = yy; } } } *(img + maxPos.y * widthstep + maxPos.x) = 0; pt.x = maxPos.x; pt.y = maxPos.y; singleEdge.push_back(pt); } } int size = singleEdge.size(); if(size > minLength) edge.push_back(singleEdge); } } } }
weixin_44941424 2020-10-21
  • 打赏
  • 举报
回复
还是做不出 啊
weixin_44941424 2020-10-20
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
先明确下 怎么定义图中的毛刺?
我用这个 https://blog.csdn.net/zzzzjh/article/details/80425248 跑出来发现去除前后图片一样,没效果不知道怎么回事
weixin_44941424 2020-10-20
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
先明确下 怎么定义图中的毛刺?
就是如图中红色圈出来的
weixin_44941424 2020-10-20
  • 打赏
  • 举报
回复
就是如图中红色圈出来的 大神们 救救孩子吧太难了,不知道怎么从端点跟踪到节点,我想的是从端点跟踪到节点并且计算长度,然后设定一个阈值小于的去掉
zgl7903 2020-10-20
  • 打赏
  • 举报
回复
先明确下 怎么定义图中的毛刺?

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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