2017-03-11 9 views
1

私は入力画像のヒストグラムを見つけようとしています。しかし、ヒストグラムを見る代わりに、コードは何も表示せずに停止します。誰かが私にこのことが起こっている理由を指摘できますか?pythonを使って入力画像のヒストグラムを見つける方法は?

import pylab as plt 
import matplotlib.image as mpimg 
import numpy as np 

img = np.uint8(mpimg.imread('jack.jpg')) 
# convert to grayscale 
# do for individual channels R, G, B, A for nongrayscale images 

img = np.uint8((0.2126* img[:,:,0]) + \ 
    np.uint8(0.7152 * img[:,:,1]) +\ 
     np.uint8(0.0722 * img[:,:,2])) 


plt.histogram(img,10) 
plt.show() 

答えて

2

あなたはhisthistogramを混乱されています。はい、plt.histogramnumpy.histogramへの呼び出しです。

このお試しください:

import pylab as plt 
import matplotlib.image as mpimg 
import numpy as np 

img = np.uint8(mpimg.imread('jack.jpg')) 
# convert to grayscale 
# do for individual channels R, G, B, A for nongrayscale images 

img = np.uint8(0.2126 * img[:,:,0]) +\ 
     np.uint8(0.7152 * img[:,:,1]) +\ 
     np.uint8(0.0722 * img[:,:,2]) 

plt.hist(img,10) 
plt.show() 

[コメントを答える編集]

ドキュメント(上記のリンク機能名の)によると、np.histogram意志Compute the histogram of a set of data、返却:

  • HISTを:arrayヒストグラムの値。 [...]
  • bin_edges:dtypeの配列 floatビンの辺(length(hist)+1)を返します。

plt.histCompute and draw the histogram of xは、タプル(n, bins, patches)を返します。

+0

ありがとうございます。しかし、私は混乱しています。 2人は同じじゃない?違いはなんですか? –

関連する問題