NumPyにはいくつかの黒(= 1)と白(= 0)の画像があります。 は、すべての2D方向で直線が並んでいる回数をカウントしたいと思います。Numpy Array:(画像からの)行内のカウント値
もう1行にないとすぐにカウントを停止したいと思います。私はラインの両側から数える必要があります。この考え方は、一方の側から直線がどれだけ長く、他方の側から真っ直ぐであるかを抽出することができるようにすることです。
以下のMWEをご覧ください。私の問題をよりよく説明してくれるでしょう。
import numpy as np
import matplotlib.pylab as plt
from matplotlib import gridspec
background = np.zeros((60,60))
one = background.copy() # straight line
one[10,5:30:1] = 1
# Here I'd like to count 25 from both directions
two = background.copy() # diagonal line, this stands for all angles the diagonal line could have, not just 45degrees!
two[[range(10,35)],[range(5,30)]] = 1
# Here I'd like to count 25 from both directions
three = background.copy() # line with right angle
three[10,5:15:1] = 1
three[10:25:1,15] = 1
# Here I'd like to count 10 from one end and 15 from the other
gs = gridspec.GridSpec(2,2)
fig = plt.figure()
line = fig.add_subplot(gs[0,0])
diag = fig.add_subplot(gs[0,1])
angle = fig.add_subplot(gs[1,0])
line.imshow(one), line.set_title('Count 25 from both sides')
diag.imshow(two), diag.set_title('Count 25 from both sides')
angle.imshow(three), angle.set_title('Count 10 from one side and 15 from the other')
私の問題は、私はGoogleでさえするのか分からないということです。
ありがとうございます!
、あなたは8「明白な」方向を意味するか、またはあなたも他の中間方向を含めるようにしたいですか? (それらは、関連するピクセルの中心が文字通り直線上にある場合、それらの8つの基本的な方向とは異なります)。 –
出力は正確には何ですか?さまざまな長さの行をさまざまな方向に入力すると、最も長い行の長さ、または各方向の最長行の長さ、または*すべての*行の長さ、または何を必要としますか? –
何が必要なのか教えてください。 (それは、どれほどの効率が重要であるかを変えるかもしれません)。 –