実現したいこと
pythonの画像処理を高速化したいです。f(x,y)をそのピクセルの画素値,l(x,y)は1だったら白、0だったら黒として
このような処理を達成するために下のコードを書いたのですが、二重ループが入っているので遅く、高速化したいです。どのように改善したら良いか、どのようなモジュールを使えばいいか、ご教示ください。
該当のソースコード
python3
1picture = cv2.imread("/Users/name/Courtemplete.png") 2gray = cv2.cvtColor(picture,cv2.COLOR_RGB2GRAY) 3σl = 180 4σd = 40 5τ = 8 6background_thresh = np.where(gray<σl,0,255).astype(np.uint8) 7for x in range(τ,picture.shape[0]-τ): 8 for y in range(τ,picture.shape[1]-τ): 9 if background_thresh[x,y]: 10 pixel = gray[x,y] 11 12 pix_candicate[x,y] = ((((pixel-gray[x+τ,y])>σd) and ((pixel-gray[x-τ,y])>σd)) or (((pixel-gray[x,y+τ])>σd) and ((pixel-gray[x,y-τ])>σd))) 13 else: 14 pix_candicate[x,y] = 0
回答1件
あなたの回答
tips
プレビュー