How to count a specific pixel number in "part of" image

asked 2018-10-21 21:50:49 -0600

dbsx gravatar image

updated 2018-10-22 03:28:19 -0600

berak gravatar image

C:\fakepath\health_bar.JPG It is easy to see the black(little transparent) part and the orange part in the image. I want to calculate the orange part pixels dynamically---as the area of orange in the bar is changing in a video.

I counted it easily with numpy like np.sum(image_np==[245,12,10]). Here [245,12,10] is one of the orange color pixel vector I detected.It is working! But problem is, sometimes the same pixel would appear in the black part,which is not easy to see for human.
I tried using Kmeans to erase the little orange pixel in the black part, but it is not working, because I realize Kmeans just clustering color without taking pixel color surrounding into account.

Then is there an approach to erase the little pixel in a image but also give results like Kmeans.

edit retag flag offensive close merge delete

Comments

You could try KMeans along with Connect Components

phillity gravatar imagephillity ( 2018-11-01 08:34:09 -0600 )edit