2017-03-20 12 views
1

私は車線を維持し、うまくいけば世界の残りの部分を取り除くことができるようにjpeg画像を色付けしようとしています。カラーはHLS jpeg画像を閾値処理する

test_image = cv2.imread(myimage) 
#convert to RGB space from BGR 
test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB) 

をその後、私は以下のようにLチャンネルを保持するために、HLS色空間へtest_image変換:私は次のようにcv2を用いて画像を読んでい

def get_l_channel_hls(img): 
    # Convert to HLS color space and separate the l channel 
    hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS).astype(np.float) 
    l_channel = hls[:,:,1] 
    return l_channel 

そして私はこれにいくつかの閾値を適用するにピクセル値を0または1に置き換えて、必要なピクセルだけを保持できるようにします。私は、このバイナリマップを取り、255

def get_overall_combined_binary(binary1): 
    grayscaled_binary = np.zeros_like(binary1) 
    grayscaled_binary [(binary1 == 1)] = 255 
    return grayscaled_binary 

を保持する画素を交換し、私はこれを表示し、その後

def get_color_channel_thresholded_binary(channel, thresh=(0,255): 
    # Threshold color channel 
    print("min color threshold: {}".format(thresh[0])) 
    print("max color threshold: {}".format(thresh[1])) 
    binary = np.zeros_like(channel) 
    binary[(channel > thresh[0]) | (channel <= thresh[1])] = 1 
    return binary 

を(私は後で保持ピクセルが白表示させるために、255で、これらの値を乗算します)以下のようにmatplotlib pyplotを使用してバイナリ:

import matplotlib.pyplot as plt 
#grayscaled_binary = # get the grayscaled binary using above APIs 
imshow(grayscaled_binary, cmap='gray') 

私がここで観察しているのはむしろ奇妙です。画像はすべてthresh[1] < thresh[0]のANY値に対してすべて黒で表示されます。すなわち、最大閾値は最小閾値よりも小さい。そして、なぜこれが起こっているのかという手がかりはありません。

私はコードを数回見直しましたが、その中にバグはありません。私がここに貼り付けたコードと、私が使用しているコードとの唯一の違いは、JupyterノートブックでIPythonウィジェットを使ってやりとりしていることです。

このトピックに関するご意見やご感想をお寄せいただきありがとうございます。 私が話していることの2つの例も付いています。 ありがとうございます。 Failure Scenario

enter image description here

答えて

1

thresh[0] < thresh[1]場合行

binary[(channel > thresh[0]) | (channel <= thresh[1])] = 1

1に全ての画素を設定します。これはあなたが望むものではないと思います。

本当にあなたが本当に必要とするものは本当に明確ではありません。 2つのしきい値内にあるピクセルが白でなければならないと仮定すると、代わりに論理andを使用します。

binary[(channel > thresh[0]) & (channel <= thresh[1])] = 1

+0

ありがとうございました! 1つのコピーペーストエラーは私に半日かかる。そして、なぜそれが以前に働いていたのだろうと思っていました。 –