2012-08-13 20 views
4

我正在使用OpenCV处理我的图像处理算法,并且正在尝试修复人物中不齐的边缘。我读到形态学命中 - 小姐转换是一个非常好的解决方案。有没有这个开源的实现?形态学撞击小姐变形

或者是否有任何其他算法可以用来修复不齐边?

Some sample letters that need fixing

+0

您可以发布图片的例子吗? – 2012-08-14 16:08:12

+0

@RégisB。张贴了一些样品 – go4sri 2012-08-16 04:04:19

+0

你在哪里阅读?我认为Hit-Miss本身还不够,你需要使用从它衍生出来的形态学操作。请参阅http://www.ee.lamar.edu/gleb/dip/10-2%20-%20Morphological%20Image%20Processing.pdf – nkint 2013-01-21 21:42:19

回答

2

的简单实现的命中和错过的可以发现here

#include <opencv2/imgproc/imgproc.hpp> 

// Hit-or-miss transform function 
void hitmiss(cv::Mat& src, // Source image, 8 bit single-channel matrix 
      cv::Mat& dst, // Destination image 
      cv::Mat& kernel) // Kernel. 1=foreground, -1=background, 0=don't care 
{ 
    CV_Assert(src.type() == CV_8U && src.channels() == 1); 

    cv::Mat k1 = (kernel == 1)/255; 
    cv::Mat k2 = (kernel == -1)/255; 

    cv::normalize(src, src, 0, 1, cv::NORM_MINMAX); 

    cv::Mat e1, e2; 
    cv::erode(src, e1, k1); 
    cv::erode(1 - src, e2, k2); 

    dst = e1 & e2; 
} 

但我认为你可以解决该问题仅出现扩张,为page 7 of this slide的例子(其取自冈萨雷斯等人的“数字图像处理”书)

0

结合形态学扩张和侵蚀使用Marvin产生的结果如下:

enter image description here

的源代码:

package characterRestoration; 

import marvin.image.MarvinColorModelConverter; 
import marvin.image.MarvinImage; 
import marvin.io.MarvinImageIO; 
import marvin.plugin.MarvinImagePlugin; 
import marvin.util.MarvinPluginLoader; 

public class CharacterRestoration { 

MarvinImage     image = MarvinImageIO.loadImage("./res/character_in.png"); 
private MarvinImagePlugin dilation = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.morphological.dilation"); 
private MarvinImagePlugin erosion = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.morphological.erosion"); 

private boolean[][]   matrixD = new boolean[][]{ 
          {false,false,false,false,false,false,false,false,false}, 
          {false,false,false,false,false,false,false,false,false}, 
          {false,false,false,false,false,false,false,false,false}, 
          {false,false,true,true,true,true,true,true,true}, 
          {false,false,true,true,true,true,true,true,true}, 
          {false,false,true,true,true,true,true,true,true}, 
          {false,false,false,false,false,false,false,false,false}, 
          {false,false,false,false,false,false,false,false,false}, 
          }; 

private boolean[][]   matrixE = new boolean[][]{ 
          {true,true,true}, 
          {true,true,true}, 
          {true,true,true} 
          };   

public CharacterRestoration(){ 
    // Convert image to binary format 
    image = MarvinColorModelConverter.rgbToBinary(image, 125); 

    // Morphological Dilation 
    dilation.setAttribute("matrix", matrixD); 
    dilation.process(image.clone(), image); 

    // Morphological Erosion 
    erosion.setAttribute("matrix", matrixE); 
    erosion.process(image.clone(), image); 

    MarvinImageIO.saveImage(image, "./res/character_out.png"); 
} 

public static void main(String[] args) { 
    new CharacterRestoration(); 
} 

}