Cleaning a scanned image in opencv

断了今生、忘了曾经 提交于 2019-12-08 12:48:37

问题


I'm trying to denoise the image then extract the skeleton of an image containing a handwritten line. I want the line to be continuous and solid but the method I use fails to do that and relatively slow. Here's the original image: Original Image

Morphed On the morphed image, you can see a small island at the lower right.

The thinned image from above shows the line is broken near the end.

Any other method to achieve desired result?

My code looks like this:

int morph_elem = 2;
int morph_size = 10;
int morph_operator = 0;

Mat origImage = imread(origImgPath, CV_LOAD_IMAGE_COLOR);
medianBlur(origImage, origImage, 3);
cvtColor(origImage, origImage, COLOR_RGB2GRAY);
threshold(origImage, origImage, 0, 255, THRESH_OTSU);

Mat element = getStructuringElement(morph_elem, Size(2 * morph_size + 1, 2 * morph_size + 1), cv::Point(morph_size, morph_size));

morphologyEx(origImage, origImage, MORPH_OPEN, element);
thin(origImage, true, true, true);

回答1:


To reduce the line break away try using adaptiveThreshold, play around with the methods and sizes and see what works best. To remove the little island simply do findContours and then mask out unwanted specs using drawContours with color=(255,255,255) and thickness=-1 after you've filtered it with something like wantedContours = [x for x in contours if contourArea(x) < 50].




回答2:


You want to perform a series of closing and opening operations on the image. It is best you understand how they work to make the appropriate choice. See this post: Remove spurious small islands of noise in an image - Python OpenCV



来源:https://stackoverflow.com/questions/39081810/cleaning-a-scanned-image-in-opencv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!