threshold_count=int(KMEANS_AREA_MASK_THRESHOLD*mask_counts[(np.argwhere(mask_colors>0))[0,0]])#select counts from white color and generate threshold with it.
threshold_count=int(KMEANS_AREA_MASK_THRESHOLD*mask_counts[(np.argwhere(mask_colors>0))[0,0]])#select counts from white color and generate threshold with it.
km_colors=km_colors[km_counts.argsort()][::-1]# sort colors by count
km_counts=km_counts[km_counts.argsort()][::-1]# sort counts by count
kmeans[((kmeans[:,:,0]==color[0])&(kmeans[:,:,1]==color[1])&(kmeans[:,:,2]==color[2]))]=filtered_km_colors[0]#search in kmeans image for specific color and replace all by first color
# kmeans[((kmeans[:,:,0] == color[0]) & (kmeans[:,:,1] == color[1]) & (kmeans[:,:,2] == color[2]))]=[0,0,255] #search in kmeans image for specific color and replace all by first color