opencv 对象骨架化

本文介绍了使用OpenCV进行图像骨架提取的两种方法:细化(thinning)和距离变换(distancetransform)。通过距离变换将二值图像的前景区域转换为灰度图像,展示从每个像素到最近边界的距离。接着,对距离变换图像应用拉普拉斯算子并设置阈值,最终获得骨架图像。为了去除噪声,建议在转换为灰度图像前进行形态学处理。

How to get the skeleton of an object using OPENCV

http://pinkjade8848.spaces.live.com/blog/cns!E4159959CD42C507!195.entry

 

Skeletonization is a process for reducing foreground regions in a binary image to a skeletal remnant that largely preserves the extent and connectivity of the original region while throwing away most of the original foreground pixels. Generally speaking, there are 2 methods to obtain the skeleton.(I am not sure there are other methods.)

thinning

distance transform

 

OpenCV doesnot provide functions for skeletonization, but provides some functions on distance transform, so I use distance transform to complete this task.

 

Distance transform is an operator normally only applied to binary images. The result of the transform is a gray level image that looks similar to the input image, except that the gray level intensities of points inside foreground regions are changed to show the distance to the closest boundary from each point

  

 

This figure show the distance transform.

 

Following steps show how it achieves:

Input:  one image

Output:  skeleton image

 

Step1:  convert the input image to grey image if the input one is a 3-channel image. convert the grey image to binary image using threshold:

            cvThreshold( src, src, 1, 255, CV_THRESH_BINARY );

 

Step 2: using distance transform functions to get the  distance transform images.

            cvDistTransform( src_img, dist_img, CV_DIST_L2,3 ,NULL,NULL );

notes :  dist_img is a 32 bit float image, so if it is be display by cvShowImage(), we will find that it is same as src_image. It is better to convert 32F image to 8U image (cvConvertScale(dist_img,dist_img_8u,1,0);), and then show it.

 

Step 3: Take Laplacian (2nd derivative) of the distance transformed image.     cvLaplace(dist_img,dist_img_laplac,3);

Step 4:  threshold the result of step 3. this is very important. Otherwise , you can not get it. (Till now. I am not sure how to select the threshold. )

 

 

It is supposed that the central  ridge in the distance transform should be the same as thee medial axis or  skeleton.

 

In order to remove noise, it is suppose to do some morphology before step 1.
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值