2016-08-30 4 views
0

画像の明るい部分を削除し、暗い部分だけを取り除くにはどうすればよいですか?opencvを使用して画像の暗い線を取得する

次の画像には、スードクゲームがあります(hereから取得)。 Adaptive Gaussian Thresholdingは本当に良い結果をもたらしますが、グレー(明るい)ラインも含みます。

注:私はcannyを試しましたが、数字も削除します。

ee

答えて

2

私はグローバルしきい値を使用して、DILATEなどの形態学的操作を使用して侵食することができるように、私は最初の背景等化を行う場合、私は最良の結果を得ることができます。

次の例では、Ubuntuの15.10でのpython 3.4およびOpenCVの3.1-devのと私のiPythonノートで動作します:

import cv2 
import numpy as np 
import matplotlib.pyplot as plt 
%matplotlib inline 

image = cv2.imread('sudokubig.jpg', 0) 

if image is None: 
    raise ValueError('Image not found!') 

# background equalization 
max_value = np.max(image) 
backgroundRemoved = image.astype(float) 
blur = cv2.GaussianBlur(backgroundRemoved, (151,151), 50) 
backgroundRemoved = backgroundRemoved/blur 
backgroundRemoved = (backgroundRemoved*max_value/np.max(backgroundRemoved)).astype(np.uint8) 


fig = plt.figure(figsize=(20, 20)) 
plt.subplot(311),plt.imshow(image, 'gray'),plt.title('Input'),plt.axis('off') 
plt.subplot(312),plt.imshow(backgroundRemoved, 'gray'),plt.title('Background Removed'),plt.axis('off') 

ret, thres = cv2.threshold(backgroundRemoved,130,255,cv2.THRESH_BINARY) 

# remove horizontal lines 
kernel = np.ones((4, 1),np.uint8) 
dilation1 = cv2.dilate(thres, kernel, iterations = 1) 

# remove vertical lines 
kernel = np.ones((1, 4),np.uint8) 
dilation2 = cv2.dilate(dilation1, kernel, iterations = 1) 

kernel = np.ones((3, 3),np.uint8) 
erosion = cv2.erode(dilation2, kernel, iterations = 1) 

plt.subplot(313),plt.imshow(erosion, 'gray'),plt.title('Final'),plt.axis('off') 
plt.show() 

kernel = np.ones((1, 4),np.uint8) 
dilation = cv2.dilate(dilation, kernel, iterations = 1) 

kernel = np.ones((3, 3),np.uint8) 
erosion = cv2.erode(dilation, kernel, iterations = 1) 

fig = plt.figure() 
plt.imshow(erosion, cmap='gray'),plt.title('missmatch') 
plt.show() 

jupyter output

たぶん、あなたは賢く方法やより良いのparamsを見つけるでしょう。私はここであなたの改善を見たいですが、私はこの短いスニペットがあなたを少し助けてくれることを願っています。

+0

ワウにぴったりです。ありがとう。 –

関連する問題