Home > Software engineering >  Fill area under the curve in a histogram
Fill area under the curve in a histogram

Time:01-08

I'm using the method of the image to generate an histogram from an image, the problem is that i need to fill the area and i can't use the function fill_between because i dont have "x" and "y" parameters, i tried using "histr" and "color=col" as axis but the program crash.

img_histogram=cv2.imread("567.jpg")
   colors = ("r")
   plt.figure()
   plt.title("Histogram")
   plt.xlabel("Bins")
   plt.ylabel("Pixels of the image")
   
   for i,col in enumerate(colors):
        histr = cv2.calcHist([img_histogram],[2],None,[256],[0,256])
        plt.plot(histr,color = col)
        plt.xlim([0,256])
        

Final histogram generated

I'm stucked and i dont know what to tried, as i mentioned before, i tried to use histr and "color=col" as axis to fill_between.

What i want to do

CodePudding user response:

You can use fill_between() method in order to do that.

plt.fill_between(np.arange(256), histr)

CodePudding user response:

Thanks to everyone for the help, i figured out how to extract the data from, histr[] is an array that contains the Y values, so now i can use it as Y variable and the array to [0,256] as an X, thanks to everyone.

  • Related