图像细化多用于机器人视觉,OCR字符识别等领域,细化后的图像经过去毛刺就成为了我们常说的图像的骨架。
该图像细化代码依据论文: T. Y. ZHANG and C. Y. SUEN A Fast Parallel Algorithm for Thinning Digital Patterns
代码如下:
void ThinSubiteration1(Mat & pSrc, Mat & pDst) {
int rows = pSrc.rows;
int cols = pSrc.cols;
pSrc.copyTo(pDst);
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
if(pSrc.at<float>(i, j) == 1.0f) {
/// get 8 neighbors
/// calculate C(p)
int neighbor0 = (int) pSrc.at<float>( i-1, j-1);
int neighbor1 = (int) pSrc.at<float>( i-1, j);
int neighbor2 = (int) pSrc.at<float>( i-1, j+1);
int neighbor3 = (int) pSrc.at<float>( i, j+1);
int neighbor4 = (int) pSrc.at<float>( i+1, j+1);
int neighbor5 = (int) pSrc.at<float>( i+1, j);
int neighbor6 = (int) pSrc.at<float>( i+1, j-1);
int neighbor7 = (int) pSrc.at<float>( i, j-1);
int C = int(~neighbor1 & ( neighbor2 | neighbor3)) +
int(~neighbor3 & ( neighbor4 | neighbor5)) +
int(~neighbor5 & ( neighbor6 | neighbor7)) +
int(~neighbor7 & ( neighbor0 | neighbor1));
今天的文章opencv笔记(二十一)——骨骼去毛刺分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/63626.html