Unverified Commit 6342aad6 authored by tilman's avatar tilman
Browse files

dilate/erosure working, but results not as wanted

parent 6f6bb182
......@@ -170,11 +170,39 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
for color in kmeans_colors[np.invert(np.isin(kmeans_colors, km_mask_colors).all(axis=1))]: #colors in kmean_out wich do not appear in any mask
kmeans_out[((kmeans_out[:,:,0] == color[0]) & (kmeans_out[:,:,1] == color[1]) & (kmeans_out[:,:,2] == color[2]))]=[0,0,0] #search in kmeans_out image for specific color and replace all by first color
cv2.namedWindow("kmeans_out", cv2.WINDOW_NORMAL)
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
#apply erosure/dilation morphing filters
# kernel = np.ones((5,5),np.uint8)
kmeans_out = cv2.medianBlur(kmeans_out,int(esz*60)+1 if int(esz*60)%2==0 else int(esz*60))
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
kernel = np.array([
[0,0,1,0,0],
[0,1,1,1,0],
[0.5,1,1,1,1],
[0,1,1,1,0],
[0,0,0.5,0,0]], dtype=np.uint8)
kmeans_out = cv2.erode(kmeans_out,kernel,iterations = 12)
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
kmeans_out = cv2.dilate(kmeans_out,kernel,iterations = 15)
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
kmeans_out = cv2.medianBlur(kmeans_out,int(esz*60)+1 if int(esz*60)%2==0 else int(esz*60))
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
kmeans_out = cv2.dilate(kmeans_out,kernel,iterations = 14)
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
kmeans_out = cv2.erode(kmeans_out,kernel,iterations = 8)
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
# kmeans_out =
# cv2.imshow(img_name+"kmeans_masked", km_mask_out)
#replace colors
......@@ -183,9 +211,6 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
# kmeans_bgfg = imgKmeans(kmeans_out, 3)
# cv2.namedWindow("kmeans_bgfg", cv2.WINDOW_NORMAL)
# cv2.imshow("kmeans_bgfg", kmeans_bgfg)
cv2.namedWindow("kmeans_out", cv2.WINDOW_NORMAL)
cv2.imshow("kmeans_out", kmeans_out)
cv2.waitKey(0)
cv2.rectangle(kmeans_out, (0,0), (235,30), (0,0,0), -1)
cv2.putText(kmeans_out, "Foreground color:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(kmeans_out, (220,15), (230,25), (int(filtered_km_mask_FG_colors[0][0]),int(filtered_km_mask_FG_colors[0][1]),int(filtered_km_mask_FG_colors[0][2])), -1)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment