检查图像中太薄的区域 [英] Check for areas that are too thin in an image
问题描述
我正在尝试验证雕刻机的黑白图像(更多的剪贴画图像 - 而不是照片)。
我需要考虑的主要事项之一是区域的大小(或线宽),因为机器无法处理太薄的线 - 所以我需要找到比给定阈值更薄的区域。
I am trying to validate black and white images (more of a clipart images - not photos) for an engraving machine.
One of the major things I need to take into consideration is the size of areas (or width of lines) since the machine can't handle lines that are too thin - so I need to find areas that are thinner than a given threshold.
拿这个例如:
竖琴的琴弦可能太薄而无法雕刻。
The strings of the harp might be too thin to engrave.
我正在阅读关于Matlab和OpenCV但是图像处理是我第一次学习的领域。
I am reading about Matlab and OpenCV but image processing is an area I am learning about for the first time.
我是一名Java / C#开发人员,因此使用其中一种语言进行的实施对我来说是最好的,但任何方向都会受到高度赞赏。
I am a Java / C# developer so implementation done with one of those languages will be best for me but any direction will be greatly appreciated.
推荐答案
定义允许区域的最小厚度,例如 minThick = 4
Define the minimal thickness of allowed area, for example, minThick=4
BW = imread('http://i.stack.imgur.com/oXKep.jpg');
BW = BW(:,:,1) < 128; %// convert image to binary mask
se = strel('disk', minTick/2, 0); %// define a disk element
eBW = imerode( BW, se ); %// "chop" half thickness from mask
deBW = imdilate( eBW, se ); %// dilate the eroded mask
侵蚀和扩张应该留下比<$ c $更厚的区域c> minThick 不变,但会删除细小区域
Eroding and dilating should leave regions that are thicker than minThick
unchanged, but it will remove the thin areas
invalidArea = BW & ~deBW; %// pixels that are in BW but not in deBW
结果:
Resulting with:
您可以阅读更多关于 imdilate
和 imerode
链接文档中的a>。
You can read more about imdilate
and imerode
in the linked documentation.
这篇关于检查图像中太薄的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!