# [Python]Manipulating histogram values

Hi! Well, i'm fairly new to Python but i have some coding background on some other languages like C. I could have gone for C++ but i wanted to learn Python so here i am, treading on unknown territory and i hope you guys can help me : )

The thing is, i've got an image:

SourceImage

And i was able to extract (most of) its background, giving me my region of interest:

ThresholdedImage

Now, i wan't to access the HSV values of the pixels in my RoI, which i did using:

hist_H = cv2.calcHist([img],[0],mask,[256],[0,256]) #For the H channel


And so on for the S and V channels (altough i'm just gonna use the H and S).

I need to get the average or predominant value of each specific channel, but using NumPy's mean/median functions compute the number of pixels, and not the value of those pixels (which are between 0 and 256). If i use the mean/median directly on the channel (say, the H channel) then it gives me the mean/median of all pixel values, but unfortunately it will compute the black pixels from my mask :/

I need this data so I can determine HSV ranges for ripe/unripe fruits and the like.

Does anyone have any idea of what could be done in this case?

edit retag close merge delete