2017-05-03 1 views
2

opencvを新しくしました。私は複数の画像を持っています。サンプル画像の1つは、左下隅に表示されています。基本的には、背景と前景を分離してエッジが鮮明になり、輪郭を適切に検出できるようにしたい。OpenCV pythonスタンプフィルターPhotoshop

私は様々なパラメータを使用して多くのフィルタともちろん閾値を試しました。私はPhotoshopのフィルターギャラリーで見ていた最後

enter image description here

は、私は私に望ましい結果(右上隅)を与えているフィルタと呼ばれるスタンプに気づきました。それはエッジをはっきりとさせ、柔らかいコーナーにある程度のぼかしを使用すると思います。

私は、Photoshopのスタンプフィルタと同じ操作をPython CV2を使ってどのように得ることができないのですか?

ご協力いただきありがとうございます。

オリジナル手つかずの画像

enter image description here

試み1: - コード

import cv2 
import numpy as np 
from matplotlib import pyplot as plt 

input_img = cv2.imread('images/Tas/t3.bmp') 
desired_img = cv2.imread('images/stamp.jpg') 

# gray scale 
gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY) 

kernel = np.ones((3,3),np.uint8) 

thresh1 = cv2.threshold(input_img,80,255,cv2.THRESH_BINARY)[1] 
erosion1 = cv2.erode(thresh1,kernel,iterations = 1) 
dilation1 = cv2.dilate(erosion1,kernel,iterations = 1) 

thresh2 = cv2.threshold(input_img,120,255,cv2.THRESH_BINARY)[1] 
erosion2 = cv2.erode(thresh2,kernel,iterations = 1) 
dilation2 = cv2.dilate(erosion2,kernel,iterations = 1) 

titles = ['Original', 'Desired','thresh1', 'erosion1','dilation1','thresh2','erosion2','dilation2'] 
images = [input_img, desired_img, thresh1, erosion1,dilation1, thresh2,erosion2, dilation2] 
for i in xrange(8): 
    plt.subplot(2,4,i+1),plt.imshow(images[i]) 
    plt.title(titles[i]) 
    plt.xticks([]),plt.yticks([]) 

plt.show() 

出力:

enter image description here

+0

2進化、恐らく浸食と膨張のように見えます。元の手つかずの画像も表示 –

+0

こんにちは@AnderBiguriちょうど元の画像を追加しました。 – VK321

+0

@アンダービグリ..どんな助け? – VK321

答えて

0

それは自分でガウスぼかしとしきい値のフィルタリングのためのスライダーのカップルを追加するために役立つかもしれないとあなたはかなりまともな結果を得ることができます。

fake "photoshop stamp" filter with gaussian blur + threshold

、ここでは、私はそれを生成するために使用される基本的な抜粋です:

import numpy as np 
import cv2 
import cv2.cv as cv 
from matplotlib import pyplot as plt 

# slider callbacks 
def printThreshold(x): 
    print "threshold",x 
def printGaussianBlur(x): 
    print "gaussian blur kernel size",x 
# make a window to add sliders/preview to 
cv2.namedWindow('processed') 
#make some sliders 
cv2.createTrackbar('threshold','processed',60,255,printThreshold) 
cv2.createTrackbar('gaussian blur','processed',3,10,printGaussianBlur) 
# load image 
img = cv2.imread('cQMgT.png',0) 
# continously process for quick feedback 
while 1: 
    # exit on ESC key 
    k = cv2.waitKey(1) & 0xFF 
    if k == 27: 
     break 

    # Gaussian Blur (x2 +1 = odd number for kernel size) 
    kernelSize = ((cv2.getTrackbarPos('gaussian blur','processed') * 2) + 1) 
    blur = cv2.GaussianBlur(img,(kernelSize,kernelSize),0) 
    # Threshold 
    ret,thresh = cv2.threshold(blur,cv2.getTrackbarPos('threshold','processed',),255,0) 
    # show result 
    cv2.imshow('processed ',thresh) 

# exit 
cv2.destroyAllWindows() 

ミックスに他のフィルタを追加して、スライダで自由に実験してください。

+0

oh @GeorgeProfenzaあなたはメイトを始めます。時間をかけてこれをやってくれてどうもありがとう。スライダーは私が思っていなかった本当にクールなアイデアでした。主なアイデアは上下の骨の分離を維持することです。私はあなたのコードでいくつかの実験を試みると確信して、結果が得られた場合にお知らせします。 – VK321

+0

甘い!答えが役に立つのであれば、あなたが合っていると自由に投票/マークすることができます;)楽しいフィルタを探索しましょう。どのような効果があったかを見てみると(あなたは既に[形態学的フィルタ](http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html)をミックスに使いたいかもしれない/ dilate、恐らく開いている/閉じるかもしれません) –