Unverified Commit 190faf55 authored by tilman's avatar tilman
Browse files

add background foreground seperation

parent c7f19c9c
......@@ -29,11 +29,13 @@ DRAW_FIRST_CONE_LAYER_BRIGTHER = True
BISEC_CONE_ANGLE = 50
CORRECTION_ANGLE = 23
OVERLAY_ALPHA = 0.2
COLORED_CANVAS = False
BISEC_SKIP_LOWER_LEVELS = False
DISPLAY_RASTER_ELEMENTS = 500
KMEANS_AREA_MASK_THRESHOLD = 0.05 #max 1.0 (percent of pixels), cur 0.09
KMEANS_AREA_MASK_THRESHOLD = 0.08 #max 1.0 (percent of pixels), cur 0.09, sonntag mittag 0.05, #smaller threshold -> more colors, higher threshold -> less colors
KMEANS_K = 7 #10
OUT_DIR = 'images/out/images_imdahl/kmeans_output_canvas/new_smaller_mask'
#KMEANS_K = 6 #10
OUT_DIR = 'images/out/images_imdahl/kmeans_output_canvas/final'
#IN_DIR = "images/first_email/" # images from first email
IN_DIR = "images/images_imdahl/" # images from imdahl
IN_DIR_BDCN = "images/out/images_imdahl/bdcn_output/"
......@@ -76,7 +78,7 @@ images_bdcn.sort()
os.chdir(OUT_DIR) #save images in this dir
#for img_name in images:
# for img_name, img_bdcn in list(zip(images, images_bdcn)):
# for img_name, img_bdcn in list(zip(images, images_bdcn)):
# for img_name, img_bdcn in list(zip(images, images_bdcn))[16:17]:
for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOSE else list(zip(images, images_bdcn))): #jesus
# for img_name, img_bdcn in list(zip(images, images_bdcn))[6:7]: #fusswaschung
# Process Image
......@@ -97,6 +99,12 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
img = datum.cvOutputData
if INPAINT_AND_KMEANS:
# general idea, people are placed in foreground
# -> inpaint around people to replace color invormation from people with color information from direct environment
# -> kmeans the result to dramatically reduce the amount of colors
# -> check witch colors are now on the position of the people. The colors participating more than 8% are considered as foreground and replaced by color with the most participation in foreground
# -> output this mask if color information with details is needed.
# -> if binary mask is needed we further do some morph filtering to get away small details and blobs
target = cv2.imread(img_name)
#remove cracks and prepare for kmeans
# target = cv2.GaussianBlur(target,(5,5),0) #unsharpen all
......@@ -107,7 +115,8 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
# target = cv2.bilateralFilter(target,13,90,90) #bring back edges and remove textures
#target = cv2.medianBlur(target,11) #smoothen cracks
target = cv2.medianBlur(target,int(esz*5)+1 if int(esz*5)%2==0 else int(esz*5)) #smoothen cracks
target = cv2.bilateralFilter(target,int(esz*25),int(esz*40),int(esz*40)) #remove cracks
target = cv2.bilateralFilter(target,int(esz*25),int(esz*40),int(esz*40)) #remove cracks
cv2.imwrite(os.path.basename(img_name)+'_inkm_step1_crackremoval.jpg',target)
fposes = np.array([np.array([line[:2] for line in pose if line[2] > 0]) for pose in datum.poseKeypoints]) #filtered poses without zero lines
mask = np.zeros((len(img),len(img[0]),1), np.uint8)
......@@ -115,6 +124,7 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
for pose in fposes: #remove bodys
convexhull = Polygon(pose).convex_hull
#inpainting
# sconvexhull = affinity.scale(convexhull, xfact=1.5, yfact=1.7, origin=convexhull.centroid)
sconvexhull = affinity.scale(convexhull, xfact=1.3, yfact=1.6, origin=convexhull.centroid)
cv2.drawContours(mask, [polyToArr(sconvexhull)], 0, 255, int(15*esz))
cv2.drawContours(mask, [polyToArr(sconvexhull)], 0, 255, -1)
......@@ -124,24 +134,26 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
cv2.drawContours(kmout_mask, [polyToArr(sconvexhull)], 0, 255, int(7*esz))
cv2.drawContours(kmout_mask, [polyToArr(sconvexhull)], 0, 255, -1)
cv2.rectangle(mask, (0,0), (len(img[0]),len(img)), 255, int(40*esz)) #remove frames
cv2.imwrite(os.path.basename(img_name)+'_inkm_step2_inpaintmask.jpg',mask)
cv2.imwrite(os.path.basename(img_name)+'_inkm_step2_kmeansresmask.jpg',kmout_mask)
inpainted = cv2.inpaint(target, mask, 3, cv2.INPAINT_TELEA)
# inpainted = cv2.medianBlur(inpainted,int(esz*5)+1 if int(esz*5)%2==0 else int(esz*5))
# inpainted = cv2.bilateralFilter(inpainted,30,40,40)
cv2.imwrite(os.path.basename(img_bdcn)+'_inpainted3.jpg',inpainted)
cv2.imwrite(os.path.basename(img_name)+'_inkm_step3_inpainted.jpg',inpainted)
#to kmeans
kmeans_out = imgKmeans(inpainted, KMEANS_K)
kmeans_output = imgKmeans(inpainted, KMEANS_K)
cv2.imwrite(os.path.basename(img_name)+'_inkm_step4_kmeansres.jpg',kmeans_output)
# cv2.imshow(img_name+"inpainted", inpainted)
# cv2.imshow(img_name+"mask", kmout_mask)
kmout_mask=cv2.cvtColor(kmout_mask,cv2.COLOR_GRAY2BGR) #change mask to a 3 channel image
km_mask_out=cv2.subtract(kmout_mask,kmeans_out)
km_mask_out=cv2.subtract(kmout_mask,kmeans_output) #subtract mask from kmeans result
km_mask_out=cv2.subtract(kmout_mask,km_mask_out)
#idea: count how many pixels the white mask has, count how many pixels each color from kmeans result appears in mask -> area > 80% is foreground
kmeans_colors, kmeans_counts = np.unique(kmeans_out.reshape(-1, kmeans_out.shape[-1]),axis=0,return_counts=True)
kmeans_colors, kmeans_counts = np.unique(kmeans_output.reshape(-1, kmeans_output.shape[-1]),axis=0,return_counts=True)
km_mask_colors, km_mask_counts = np.unique(km_mask_out.reshape(-1, km_mask_out.shape[-1]),axis=0,return_counts=True)
mask_colors, mask_counts = np.unique(kmout_mask.reshape(-1, kmout_mask.shape[-1]),axis=0,return_counts=True)
......@@ -159,98 +171,119 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
filtered_km_mask_BG_colors = km_mask_colors[np.argwhere(km_mask_counts<threshold_count)]
filtered_km_mask_BG_colors = filtered_km_mask_BG_colors[np.sum(filtered_km_mask_BG_colors, axis=2)>0] #filter out black from mask
kmeans_temp_save = kmeans_out.copy()
cv2.putText(km_mask_out, "Foreground colors:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(kmeans_temp_save, (0,0), (235,30), (0,0,0), -1)
cv2.putText(kmeans_temp_save, "Foreground color:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(kmeans_temp_save, (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)
cv2.rectangle(kmeans_temp_save, (220,15), (230,25), (255,255,255), 1)
cv2.imwrite(os.path.basename(img_bdcn)+'_km_mask_out_before.jpg',kmeans_temp_save)
offset=220;
for color in filtered_km_mask_FG_colors:
#print colors on screen
print("filtered_km_mask_FG_colors",color)
x = offset
y = 15
offset += 15
#replace colors
# kmeans_out[((kmeans_out[:,:,0] == color[0]) & (kmeans_out[:,:,1] == color[1]) & (kmeans_out[:,:,2] == color[2]))]=filtered_km_mask_FG_colors[0] #search in kmeans image for specific color and replace all by first color
kmeans_out[((kmeans_out[:,:,0] == color[0]) & (kmeans_out[:,:,1] == color[1]) & (kmeans_out[:,:,2] == color[2]))]=[255,255,255] #search in kmeans_out image for specific color and replace all by first color
kmeans_temp_save[((kmeans_temp_save[:,:,0] == color[0]) & (kmeans_temp_save[:,:,1] == color[1]) & (kmeans_temp_save[:,:,2] == color[2]))]=filtered_km_mask_FG_colors[0] #search in kmeans_temp_save image for specific color and replace all by first color
# km_mask_out[((km_mask_out[:,:,0] == color[0]) & (km_mask_out[:,:,1] == color[1]) & (km_mask_out[:,:,2] == color[2]))]=filtered_km_mask_FG_colors[0] #search in kmeans_out image for specific color and replace all by first color
cv2.rectangle(km_mask_out, (x,y), (x+10,y+10), (int(color[0]),int(color[1]),int(color[2])), -1)
for color in filtered_km_mask_BG_colors:
print("filtered_km_mask_BG_colors",color)
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
# kmeans_out[((kmeans_out[:,:,0] == color[0]) & (kmeans_out[:,:,1] == color[1]) & (kmeans_out[:,:,2] == color[2]))]=filtered_km_mask_BG_colors[0] #search in kmeans_out image for specific color and replace all by first color
# km_mask_out[((km_mask_out[:,:,0] == color[0]) & (km_mask_out[:,:,1] == color[1]) & (km_mask_out[:,:,2] == color[2]))]=filtered_km_mask_BG_colors[0] #search in kmeans_out image for specific color and replace all by first color
colors_only_BG = 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
for color in colors_only_BG:
print("colors_only_BG",color)
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
# kmeans_temp_save[((kmeans_temp_save[:,:,0] == color[0]) & (kmeans_temp_save[:,:,1] == color[1]) & (kmeans_temp_save[:,:,2] == color[2]))]=colors_only_BG[0] #search in kmeans_temp_save image for specific color and replace all by first color
# km_mask_out[((km_mask_out[:,:,0] == color[0]) & (km_mask_out[:,:,1] == color[1]) & (km_mask_out[:,:,2] == color[2]))]=colors_only_BG[0] #search in kmeans_out image for specific color and replace all by first color
#remove small kmeans fragments
kmeans_temp_save = cv2.medianBlur(kmeans_temp_save,7)
cv2.rectangle(kmeans_temp_save, (0,0), (235,30), (0,0,0), -1)
cv2.putText(kmeans_temp_save, "Foreground color:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(kmeans_temp_save, (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)
cv2.rectangle(kmeans_temp_save, (220,15), (230,25), (255,255,255), 1)
cv2.imwrite(os.path.basename(img_bdcn)+'_kmeans_temp_save_after.jpg',kmeans_temp_save)
cv2.imwrite(os.path.basename(img_bdcn)+'_km_mask_out.jpg',km_mask_out)
# 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)
#reprint text because medianBlur destroys it
# 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))
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
# kmeans_out = cv2.medianBlur(kmeans_out,53)
# kmeans_out = cv2.bilateralFilter(kmeans_out,30,60,60)
# kmeans_bgfg = imgKmeans(kmeans_out, 3)
# cv2.namedWindow("kmeans_bgfg", cv2.WINDOW_NORMAL)
# cv2.imshow("kmeans_bgfg", kmeans_bgfg)
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)
cv2.rectangle(kmeans_out, (220,15), (230,25), (255,255,255), 1)
output_canvas = kmeans_out
if(len(filtered_km_mask_FG_colors)>0): #we can not do anything if we have no foreground colors
cv2.putText(km_mask_out, "Foreground colors:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(kmeans_output, (0,0), (235,30), (0,0,0), -1)
cv2.putText(kmeans_output, "Foreground color:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(kmeans_output, (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)
cv2.rectangle(kmeans_output, (220,15), (230,25), (255,255,255), 1)
# cv2.imwrite(os.path.basename(img_bdcn)+'_km_mask_out_before.jpg',kmeans_output)
binary_output = kmeans_output.copy()
offset=220;
for color in filtered_km_mask_FG_colors:
#print colors on screen
print("filtered_km_mask_FG_colors",color)
x = offset
y = 15
offset += 15
#replace colors
# binary_output[((binary_output[:,:,0] == color[0]) & (binary_output[:,:,1] == color[1]) & (binary_output[:,:,2] == color[2]))]=filtered_km_mask_FG_colors[0] #search in kmeans image for specific color and replace all by first color
binary_output[((binary_output[:,:,0] == color[0]) & (binary_output[:,:,1] == color[1]) & (binary_output[:,:,2] == color[2]))]=[255,255,255] #search in binary_output image for specific color and replace all by first color
kmeans_output[((kmeans_output[:,:,0] == color[0]) & (kmeans_output[:,:,1] == color[1]) & (kmeans_output[:,:,2] == color[2]))]=filtered_km_mask_FG_colors[0] #search in kmeans_output image for specific color and replace all by first color
# km_mask_out[((km_mask_out[:,:,0] == color[0]) & (km_mask_out[:,:,1] == color[1]) & (km_mask_out[:,:,2] == color[2]))]=filtered_km_mask_FG_colors[0] #search in binary_output image for specific color and replace all by first color
cv2.rectangle(km_mask_out, (x,y), (x+10,y+10), (int(color[0]),int(color[1]),int(color[2])), -1)
for color in filtered_km_mask_BG_colors:
print("filtered_km_mask_BG_colors",color)
binary_output[((binary_output[:,:,0] == color[0]) & (binary_output[:,:,1] == color[1]) & (binary_output[:,:,2] == color[2]))]=[0,0,0] #search in binary_output image for specific color and replace all by first color
# binary_output[((binary_output[:,:,0] == color[0]) & (binary_output[:,:,1] == color[1]) & (binary_output[:,:,2] == color[2]))]=filtered_km_mask_BG_colors[0] #search in binary_output image for specific color and replace all by first color
# km_mask_out[((km_mask_out[:,:,0] == color[0]) & (km_mask_out[:,:,1] == color[1]) & (km_mask_out[:,:,2] == color[2]))]=filtered_km_mask_BG_colors[0] #search in binary_output image for specific color and replace all by first color
colors_only_BG = 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
for color in colors_only_BG:
print("colors_only_BG",color)
binary_output[((binary_output[:,:,0] == color[0]) & (binary_output[:,:,1] == color[1]) & (binary_output[:,:,2] == color[2]))]=[0,0,0] #search in binary_output image for specific color and replace all by first color
# kmeans_output[((kmeans_output[:,:,0] == color[0]) & (kmeans_output[:,:,1] == color[1]) & (kmeans_output[:,:,2] == color[2]))]=colors_only_BG[0] #search in kmeans_output image for specific color and replace all by first color
# km_mask_out[((km_mask_out[:,:,0] == color[0]) & (km_mask_out[:,:,1] == color[1]) & (km_mask_out[:,:,2] == color[2]))]=colors_only_BG[0] #search in binary_output image for specific color and replace all by first color
cv2.imwrite(os.path.basename(img_name)+'_inkm_step5_kmean_colorreplaced.jpg',kmeans_output)
cv2.imwrite(os.path.basename(img_name)+'_inkm_step5_kmean_binarization.jpg',binary_output)
# cv2.imwrite(os.path.basename(img_bdcn)+'_kmeans_output_after.jpg',kmeans_output)
# cv2.imwrite(os.path.basename(img_bdcn)+'_km_mask_out.jpg',km_mask_out)
# cv2.namedWindow("binary_output", cv2.WINDOW_NORMAL)
# cv2.imshow("binary_output", binary_output)
# cv2.waitKey(0)
#apply erosure/dilation morphing filters
# kernel = np.ones((5,5),np.uint8)
#reprint text because medianBlur destroys it
# cv2.imshow("binary_output", binary_output)
# cv2.waitKey(0)
if COLORED_CANVAS:
#remove small kmeans fragments
kmeans_output = cv2.medianBlur(kmeans_output,7)
cv2.rectangle(kmeans_output, (0,0), (235,30), (0,0,0), -1)
cv2.putText(kmeans_output, "Foreground color:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(kmeans_output, (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)
cv2.rectangle(kmeans_output, (220,15), (230,25), (255,255,255), 1)
cv2.imwrite(os.path.basename(img_name)+'_inkm_step6_kmean_fragementsremoved.jpg',kmeans_output)
output_canvas = kmeans_output
else:
# try:
# #medianblur randomly crashes. we can also continue without
# binary_output = cv2.medianBlur(binary_output,int(esz*60)+1 if int(esz*60)%2==0 else int(esz*60))
# finally:
# pass
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)
binary_output = cv2.dilate(binary_output,kernel,iterations = 10)
binary_output = cv2.erode(binary_output,kernel,iterations = 10)
# cv2.imshow("binary_output", binary_output)
# cv2.waitKey(0)
# cv2.imshow("binary_output", binary_output)
# cv2.waitKey(0)
cv2.imwrite(os.path.basename(img_name)+'_inkm_step6_1_kmean_morphclose.jpg',binary_output)
# binary_output = cv2.medianBlur(binary_output,int(esz*60)+1 if int(esz*60)%2==0 else int(esz*60))
# cv2.imwrite(os.path.basename(img_name)+'_inkm_step6_2_kmean_morpblurred.jpg',binary_output)
# cv2.imshow("binary_output", binary_output)
# cv2.waitKey(0)
binary_output = cv2.erode(binary_output,kernel,iterations = 10)
binary_output = cv2.dilate(binary_output,kernel,iterations = 10)
# cv2.imshow("binary_output", binary_output)
# cv2.waitKey(0)
cv2.imwrite(os.path.basename(img_name)+'_inkm_step6_2_kmean_morpopen.jpg',binary_output)
# cv2.imshow("binary_output", binary_output)
# cv2.waitKey(0)
# binary_output =
# cv2.imshow(img_name+"kmeans_masked", km_mask_out)
#replace colors
# binary_output = cv2.medianBlur(binary_output,53)
# binary_output = cv2.bilateralFilter(binary_output,30,60,60)
# kmeans_bgfg = imgKmeans(binary_output, 3)
# cv2.namedWindow("kmeans_bgfg", cv2.WINDOW_NORMAL)
# cv2.imshow("kmeans_bgfg", kmeans_bgfg)
cv2.rectangle(binary_output, (0,0), (235,30), (0,0,0), -1)
cv2.putText(binary_output, "Foreground color:", (10,25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255))
cv2.rectangle(binary_output, (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)
cv2.rectangle(binary_output, (220,15), (230,25), (255,255,255), 1)
output_canvas = binary_output
else:
print("WARNING: skipped fg/bg calc")
if BDCN_EDGES:
......@@ -352,12 +385,15 @@ for img_name, img_bdcn in (list(zip(images, images_bdcn))[15:16] if SKIP_OPENPOS
if SAVE_FILE:
cv2.imwrite(os.path.basename(img_name),img)
cv2.imwrite(os.path.basename(img_bdcn)+'_canvas_erosureDilate2.jpg',output_canvas)
if COLORED_CANVAS:
cv2.imwrite(os.path.basename(img_bdcn)+'_final_colored_canvas.jpg',output_canvas)
else:
cv2.imwrite(os.path.basename(img_bdcn)+'_final_binary_canvas.jpg',output_canvas)
if SHOW_WINDOW:
cv2.namedWindow(img_name, cv2.WINDOW_NORMAL)
cv2.imshow(img_name, img)
cv2.namedWindow("canvas", cv2.WINDOW_NORMAL)
cv2.imshow("canvas", output_canvas)
cv2.namedWindow(img_bdcn+"canvas", cv2.WINDOW_NORMAL)
cv2.imshow(img_bdcn+"canvas", output_canvas)
cv2.waitKey(0)
if SHOW_WINDOW:
cv2.waitKey(0)
......
import cv2
import numpy as np
# out = cv2.imread('../images/images_imdahl/Giotto_di_Bondone_-_Joachims_Dream_-_Capella_degli_Scrovegni.jpg')
out = cv2.imread('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/art-structures-env/src/images/out/images_imdahl/kmeans_output_canvas/new2/658px-Giotto_di_Bondone_-_No._3_Scenes_from_the_Life_of_Joachim_-_3._Annunciation_to_St_Anne_-_WGA09171.png_kmeans_temp_save_after.jpg')
out = cv2.imread('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/art-structures-env/src/images/out/images_imdahl/kmeans_output_canvas/final/658px-Giotto_di_Bondone_-_No._3_Scenes_from_the_Life_of_Joachim_-_3._Annunciation_to_St_Anne_-_WGA09171.jpg_inkm_step5_kmean_binarization.jpg')
# out = cv2.GaussianBlur(out,(5,5),0)
# out = cv2.medianBlur(out,3) #smoothen cracks
out = cv2.medianBlur(out,13) #smoothen cracks
out = cv2.bilateralFilter(out,30,60,60) #remove cracks
out = cv2.medianBlur(out,13) #smoothen cracks
#remove small kmeans fragments
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)
# out = cv2.medianBlur(out,53)
# out = cv2.medianBlur(out,53)
out = cv2.erode(out,kernel,iterations = 10)
out = cv2.dilate(out,kernel,iterations = 10)
out = cv2.dilate(out,kernel,iterations = 10)
out = cv2.erode(out,kernel,iterations = 10)
# out = cv2.bilateralFilter(out,20,60,60)
# out = cv2.medianBlur(out,7)
# out = cv2.medianBlur(out,13) #smoothen cracks
# out = cv2.bilateralFilter(out,30,90,90) #remove cracks
......
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