Morphological mission

I use OpenCV for my image processing algorithms and try to fix the ragged edges in characters. I read that the hit-miss morphological transformation is a very good solution for this. Is there any open source implementation?

Or is there any other algorithm that can be used to fix dangling edges?

Some sample letters that need fixing

+4
source share
2 answers

A simple hit and miss implementation can be found 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; } 

But I think that you can solve the problem only with the extension, as an example in page 7 of this slide (this is taken from "Digital Image Processing" from Gonzales and others)

+2
source

Combined morphological dilatation and erosion using Marvin led to the following result:

enter image description here

Source:

 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(); } 

}

0
source

All Articles