查找黑白图像的边缘 [英] Find edge of black and white image

查看:49
本文介绍了查找黑白图像的边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到边缘并生成黑白图像的点,如下所示:

我不确定该怎么做.我知道OpenCV是一个选择,但是对于肯定会是一个简单任务的方法来说,这太过分了.有谁知道任何简单的方法来做到这一点?图书馆还可以,只要它们不是太重(仅首选标题)

解决方案

我将使用Canny Edge Detection,尽管您可以轻松地尝试@therainmaker建议的其他功能.我会使用ImageMagick,它是免费的,安装在大多数Linux发行版中,并且也适用于OS X和Windows.

在命令行中,您将使用以下代码:

 转换blob.png -canny 0x1 + 10%+ 30%result.png 

或者这个:

 转换blob.png -canny 0x1 + 10%+ 30%-negate result.png 

要与C ++一起使用,您可以使用 Magick ++ ,在

此处进行了很好的描述.

如果要将轮廓作为矢量路径,则可以通过中间的 PBM 文件将 ImageMagick potrace 组合在一起,如下所示:

  convert blob.png -canny 0x1 + 10%+ 30%-negate pbm:-|potrace -s -o result.svg 

这将为您提供一个很好的平滑矢量路径,如下所示:

 <?xml version ="1.0" standalone ="no"?><!DOCTYPE svg PUBLIC-//W3C//DTD SVG 20010904//EN""http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">< svg version ="1.0" xmlns ="http://www.w3.org/2000/svg"width ="745.000000pt" height ="1053.000000pt" viewBox ="0 0 745.000000 1053.000000"reserveAspectRatio ="xMidYMid Meet"><元数据>由Potrace 1.12创建,彼得·塞林格(Peter Selinger)撰写,2001-2015年</元数据>< g transform ="translate(0.000000,1053.000000)scale(0.100000,-0.100000)"fill =#000000" stroke ="none">< path d ="M6145 8276 c-159 -39 -545 -231 -975 -485 -276 -163 -313 -179 -630-267 -567 -157 -1108 -385 -1550 -652 -182 -111 -178 -107 -359 -289 -173-174 -351 -387 -483 -579 -42 -61 -84 -116 -92 -123 -8 -7 -18 -25 -21 -41 -3-16 -13 -34 -21 -41 -8 -7 -27 -33 -41 -58 -14 -25 -41 -68 -58 -96 -18 -27-48 -81 -66 -120 -18 -38 -44 -83 -57 -100 -38 -46 -183 -353 -246 -516 -142-373 -156 -550 -76 -979 76 -403 215 -867 299 -999 40 -62 121 -138 167 -15758 -24 119 -32 179 -22 74 11 276 94 775 316 423 188 561 243 900 362 568 1991059 434 1478 706 261 170 403 298 552 496 261 346 439 756 494 1138 38 26172 696 81 1025 8 272 17 342 72 554 85 332 112 563 79 691 -49 188 -210 283-401 236z m221 -27 c64 -30 115 -84 150 -155 28 -57 29 -64 28 -199 0 -165-16 -262 -84 -531 -59 -229 -67 -295 -75 -569 -13 -471 -64 -995 -120 -1230-86 -363 -361 -858 -621 -1119 -229 -229 -721 -529 -1279 -778 -220 -99 -319-138 -615 -242 -340 -120 -556 -208 -1001 -406 -581 -260 -633 -278 -736 -259-103 20 -207 116 -273 253 -106 221 -260 821 -301 1176 -35 311 335782731062 37 75 78 149 91 165 12 15 38 60 56 98 18 39 48 93 66 120 17 28 44 7158 96 14 25 33 51 41 58 8 7 18 25 21 41 3 16 13 34 21 41 8 7 50 62 92123207 300 562 688 732 801 45 30 85 55 88 55 3 0 37 20 76 44 375 232 967 4781521 631 268 74 353 108 535 216 333 197 793 440 927 491 143 54 243 59 32917z"/></g></svg> 

I need to find the edge and generate points of a black and white image like the one below:

I am not sure how to go about doing this. I know OpenCV is an option, but that is way overkill for what is sure to be a simple task. Does anyone know any easy way to do this? Libraries are okay, as long as they aren't too heavyweight (header only preferred)

解决方案

I would use a Canny Edge Detection, though you can easily experiment with the others that @therainmaker suggests. I would use ImageMagick which is free and installed on most Linux distros and also available for OS X and Windows.

At the command line, you would use this:

convert blob.png -canny 0x1+10%+30%  result.png

or this:

convert blob.png -canny 0x1+10%+30% -negate result.png

To use with C++, you would use Magick++, which is described here. There is a reasonable tutorial here.

If you want a description of the theory and examples of usage, including Sobel etc, please look at Anthony Thyssen's excellent pages here.

Depending on what you are actually doing, you may be better served by a Morphological technique (shape detection) rather than an Edge Detection technique. If so, ImageMagick can do that for you also. For example:

convert blob.png -morphology EdgeIn Octagon edgein.png

That technique is described nicely here.

If, you want the outline as a vector path, you can combine ImageMagick and potrace through an intermediate PBM file like this:

convert blob.png -canny 0x1+10%+30% -negate pbm:- | potrace -s -o result.svg

That will give you a nice smooth vector path like this:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
 width="745.000000pt" height="1053.000000pt" viewBox="0 0 745.000000 1053.000000"
 preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.12, written by Peter Selinger 2001-2015
</metadata>
<g transform="translate(0.000000,1053.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M6145 8276 c-159 -39 -545 -231 -975 -485 -276 -163 -313 -179 -630
-267 -567 -157 -1108 -385 -1550 -652 -182 -111 -178 -107 -359 -289 -173
-174 -351 -387 -483 -579 -42 -61 -84 -116 -92 -123 -8 -7 -18 -25 -21 -41 -3
-16 -13 -34 -21 -41 -8 -7 -27 -33 -41 -58 -14 -25 -41 -68 -58 -96 -18 -27
-48 -81 -66 -120 -18 -38 -44 -83 -57 -100 -38 -46 -183 -353 -246 -516 -142
-373 -156 -550 -76 -979 76 -403 215 -867 299 -999 40 -62 121 -138 167 -157
58 -24 119 -32 179 -22 74 11 276 94 775 316 423 188 561 243 900 362 568 199
1059 434 1478 706 261 170 403 298 552 496 261 346 439 756 494 1138 38 261
72 696 81 1025 8 272 17 342 72 554 85 332 112 563 79 691 -49 188 -210 283
-401 236z m221 -27 c64 -30 115 -84 150 -155 28 -57 29 -64 28 -199 0 -165
-16 -262 -84 -531 -59 -229 -67 -295 -75 -569 -13 -471 -64 -995 -120 -1230
-86 -363 -361 -858 -621 -1119 -229 -229 -721 -529 -1279 -778 -220 -99 -319
-138 -615 -242 -340 -120 -556 -208 -1001 -406 -581 -260 -633 -278 -736 -259
-103 20 -207 116 -273 253 -106 221 -260 821 -301 1176 -35 311 33 578 273
1062 37 75 78 149 91 165 12 15 38 60 56 98 18 39 48 93 66 120 17 28 44 71
58 96 14 25 33 51 41 58 8 7 18 25 21 41 3 16 13 34 21 41 8 7 50 62 92 123
207 300 562 688 732 801 45 30 85 55 88 55 3 0 37 20 76 44 375 232 967 478
1521 631 268 74 353 108 535 216 333 197 793 440 927 491 143 54 243 59 329
17z"/>
</g>
</svg>

这篇关于查找黑白图像的边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆