2017-03-27 27 views
3

私はKNNメソッドを使用して、顔写真に基づいて人々を人種に分類しようとしています。私は純粋な白い背景に顔のデータセットを持っています[255,255,255]。純粋な白の色ヒストグラムへの影響

フィード入力として、私はカラーヒストグラムの値を使用しています。 KNNのパフォーマンスを向上させるためにヒストグラムから背景色を削除する必要があると言われました。

問題:写真から背景を無視したマスクを作成すると、ヒストグラムが1つ小さなビットに変化することはありません。

質問:私は色の理論にはあまり関係がありません。純粋な白色が色のヒストグラムの形にまったく影響しますか?私は、(下の画像のように)ヒストグラムが変化するだけの中心的なマスクを使用します。

Constructed mask - no change to histogram

これはマスクアプリケーション

Original image

ソース画像の正しさをテストするための背景

Simple mask - changes histogram

単純なマスクを無視して、Iピクチャから構成マスクでありますヒストグラムカウントの場合

Original and constructed mask histogram これは、マスクを使用していない画像と、白色を無視して作成したマスクから得たヒストグラムです。

Simple mask histogram これは私の単純なマスクを使用して画像を切り抜くことから得られるヒストグラムです。ヒストグラムの変化、私はヒストグラムをカウントするための私の方法が正しいと仮定します。マスクを作成するための

# loop over the image channels 
for (chan, color) in zip(channels, colors): 
    # create a histogram for the current channel and 
    # concatenate the resulting histograms for each channel 
    hist_full = opencv.calcHist([chan], [0], mask, [bin_amount], [0, bin_amount]) 

    # plot the histogram 
    plt.plot(hist_full, color=color) 
    plt.xlim([0, bin_amount]) 

plt.show() 

コード:ヒストグラムをカウントする

コード

mask = np.zeros(image.shape[:2], np.uint8) 
    # simple mask option 
    # mask[75:175, 75:175] = 255 


    # create a mask to ignore white background in the histogram 
    for row in range(0, len(image)): 

     for col in range(0, len(image[0])): 

      if (image[row][col] != np.asarray(prop.background)).all(): 
       try: 
        mask[row][col] = 255 
       except IndexError: 
        print(col) 

答えて

3

参照:http://docs.opencv.org/2.4/modules/imgproc/doc/histograms.html

重要な部分:

のPython:cv2.calcHist(画像、チャンネル、マスク、 histSize、ranges [、hist [、accumulate]])→hist

パラメータ:... 範囲 - 各次元のヒストグラムbin境界のdims配列の配列。ヒストグラムが一様(均一=真)である場合、各次元iについて、0番目のヒストグラムビンの下位(包括)境界L_0と上位(排他)境界U_ {\ texttt {histSize} [ i] -1}の最後のヒストグラムbin histSize [i] -1。

hist_full = opencv.calcHist([chan], [0], mask, [bin_amount], [0, 256]) 

を次のように

はあなたのコードのこの部分に

hist_full = opencv.calcHist([chan], [0], mask, [bin_amount], [0, bin_amount]) 

を変更してみます(上限排他)画像で実際の値の範囲を指定する必要があります。 おそらく、ヒストグラムで0〜63の値のみをカウントし、64〜255は無視します。

+0

多くのお役に立っていただきありがとうございます。 –

関連する問題