如何从二进制图像中消除不必要的黑度(主要是由暗区/噪声引起的) [英] How do you remove the unnecessary blackness from binary images (mainly caused by dark areas/noise)

查看:74
本文介绍了如何从二进制图像中消除不必要的黑度(主要是由暗区/噪声引起的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究教科书页面的图像(例如问题和手写笔记),并且想要用于OCR等少数几个不同任务的二进制图像.但是问题是,如果图像有些阴影或亮度水平不连续,则会给我很多黑色区域覆盖文本.

I am working on Images of Textbook pages such as questions and handwritten notes and want the binary image for that for few different tasks mainly the OCR. But the problem is that if an image is having a bit of shadow or the brightness level is not continuous, it gives me a lot of black area covering my text.

我从skimage.filters中的导入了我的图像上的try_all_threshold ,发现某些图像可以很好地处理某些图像,而其他图像则不能.我不能在必须根据不同图像更改参数的地方使用本地阈值,因为我想自动化OCR的过程.

I used from skimage.filters import try_all_threshold on my images and found that some work well with certain kind of images, others dont. I can not use Local Thresholding where I have to change parameters based on different images because I want to automate the process of OCR.

img_path = DIR+str(11)+'.png'
sk_image = imread(img_path,as_gray=True)

fig,ax = try_all_threshold(sk_image,figsize=(20,15))
plt.savefig('threshold.jpeg',dpi=350)

为什么图像中会形成黑色区域,我该如何去除??

诸如 Bilateral Gauss 之类的去噪过滤器会做吗?如果没有,请提出其他建议?

Will a denoising filter such as Bilateral or Gauss would do? If not,please suggest some other technique?

推荐答案

这是在Python/OpenCV中使用除法归一化的一种方法.

Here is one way to do that in Python/OpenCV using division normalization.

  • 阅读输入内容
  • 转换为灰色
  • 具有高斯模糊的平滑
  • 通过平滑图像划分灰度图像
  • 应用锐化蒙版以锐化
  • 应用Otsu阈值
  • 保存结果

输入:

import cv2
import numpy as np
import skimage.filters as filters

# read the image
img = cv2.imread('math.png')

# convert to gray
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# blur
smooth = cv2.GaussianBlur(gray, (95,95), 0)

# divide gray by morphology image
division = cv2.divide(gray, smooth, scale=255)

# sharpen using unsharp masking
sharp = filters.unsharp_mask(division, radius=1.5, amount=1.5, multichannel=False, preserve_range=False)
sharp = (255*sharp).clip(0,255).astype(np.uint8)

# threshold
thresh = cv2.threshold(sharp, 0, 255, cv2.THRESH_OTSU )[1] 

# save results
cv2.imwrite('math_division.jpg',division)
cv2.imwrite('math_division_sharp.jpg',sharp)
cv2.imwrite('math_division_thresh.jpg',division)

# show results
cv2.imshow('smooth', smooth)  
cv2.imshow('division', division)  
cv2.imshow('sharp', sharp)  
cv2.imshow('thresh', thresh)  
cv2.waitKey(0)
cv2.destroyAllWindows()

部门图片:

图片锐化:

阈值图像:

这篇关于如何从二进制图像中消除不必要的黑度(主要是由暗区/噪声引起的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆