图像处理之计算连通区域的角度方向

一:基本原理

基于空间Moment算法在图像处理与分析中寻找连通区域计算连通区域的中心与角度方

Moment的一阶可以用来计算区域的中心质点,二阶可以用来证明图像的几个不变性

如旋转不变行,放缩不变性等。基于Moment的二阶计算结果,根据如下公式:

20140126175747250

可以得到区域的方向角度。

二:算法流程

1.      读入图像数据

2.      根据连通组件标记算法得到区域

3.      根据中心化Moment算法计算角度

4.      根据中心离心值画出渲染×××线条

三:算法演示效果

图像处理之计算连通区域的角度方向_第1张图片


四:算法主要源代码

package com.gloomyfish.p_w_picpath.moments; 
    
import java.awt.p_w_picpath.BufferedImage; 
    
import com.gloomyfish.filter.study.AbstractBufferedImageOp; 
import com.gloomyfish.rice.analysis.FastConnectedComponentLabelAlg; 
    
public class DirectionRegionMoments extends AbstractBufferedImageOp { 
    
    @Override 
    public BufferedImage filter(BufferedImage src, BufferedImage dest) { 
        int width = src.getWidth(); 
        int height = src.getHeight(); 
    
        if ( dest == null ) 
            dest = createCompatibleDestImage( src, null ); 
    
        // first step - make it as binary p_w_picpath output pixel 
        int[] inPixels = new int[width*height]; 
        int[] outPixels = new int[width*height]; 
        getRGB( src, 0, 0, width, height, inPixels ); 
        int index = 0; 
        for(int row=0; row> 16) & 0xff; 
                if(tr > 127) 
                { 
                     outPixels[index] = 1; 
                } 
                else 
                { 
                    outPixels[index] = 0; 
                } 
            } 
        } 
            
        // second step, connected component labeling algorithm 
        FastConnectedComponentLabelAlg ccLabelAlg = new FastConnectedComponentLabelAlg(); 
        ccLabelAlg.setBgColor(0); 
        int[] labels = ccLabelAlg.doLabel(outPixels, width, height); 
        int max = 0; 
        for(int i=0; i用到的其它JAVA类代码请参见这里:

http://blog.csdn.net/jia20003/article/details/17596645