как убрать шум на фоне старого изображения документа - PullRequest
2 голосов
/ 19 апреля 2020

как удалить фон изображения, которое содержит много шумов и линий и т. Д. c

[sample image][1]
import cv2
from PIL import Image
image = cv2.imread("1.jpg") #input image
image = cv2.fastNlMeansDenoisingColored(image,None,10,10,7,21)
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) #to gray scale
res,thresh = cv2.threshold(gray,150,255,cv2.THRESH_BINARY_INV) #to binary using threshold
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3)) 
dilated = cv2.dilate(thresh,kernel,iterations = 5) #dilation operation

есть ли другие операции предварительной обработки для удаления шумов

_,contours, hierarchy = cv2.findContours(dilated,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #finding contours
print(1)
coord = []
#contours greater than or less than specified size is removed
for contour in contours:  
      [x,y,w,h] = cv2.boundingRect(contour)   


      if h>300 and w>300:   
          continue   
      if h<100 or w<100:   
          continue  
      coord.append((x,y,w,h)) 
count = 0
for cor in coord:
        [x,y,w,h] = cor
        t = image[y:y+h,x:x+w,:].astype('uint8')
      cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
        plt.imshow(cv2.resize(t, (150, 150)))
        plt.show()
        count=count+1
print("number of char in image:", count)

есть Любой способ удалить шумы, пожалуйста, помогите

enter image description here

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...