python - How to properly use matplotlib render an image histogram? -
i'm trying write python small program obtain grayscale histogram image. i'm using opencv , matplotlib i'm not getting results when trying display graph.
this i'm doing:
- convert grayscale.
- create 256 length list of zeros.
- iterate on each pixel, grayscale value , increment in 1 value of list @ same position in list of pixel grayscale value.
- later, try use matplotlib
hist
function. i'm not getting expected result.
this i'm trying:
img = cv2.imread(sys.argv[1], 0) # cv2.imshow("imagen",img) height, width = img.shape print height print width hist = [0] * 256 print hist y in xrange(height): x in xrange(width): pixel = img[y,x] hist[pixel] = hist[pixel] + 1 print hist print max(hist) pyplot.hist(hist,256, range=(0,255)) pyplot.show()
i printed min , max value , max 4001, , i'm obtaining.
how can obtain proper plot?
note: know there , other implementations opencv in case have code myself.
you don't want pyplot.hist(hist,256, range=(0,255))
, since trying aggregate data you, you've aggregated yourself.
try this
pyplot.plot(hist)
Comments
Post a Comment