Unverified Commit 071cf799 authored by tilman's avatar tilman
Browse files

add some playground/test files

parent eb193ec3
......@@ -3,32 +3,50 @@ import cv2
import os
IN_DIR = "../images/first_email/"
IN_DIR = "../images/images_imdahl/"
images = [os.path.join(os.getcwd(), IN_DIR, f) for f in os.listdir(IN_DIR)]
os.chdir('../images/out/first_email/kmeans_k2/') #save images in this dir
os.chdir('../images/out/images_imdahl/filtered_median/') #save images in this dir
for img_name in images:
# img_name=images[0]
print(img_name)
img = cv2.imread(img_name)
# img = cv2.imread(img_name)
Z = img.reshape((-1,3))
# cv2.imshow('res2'+img_name,img)
# cv2.waitKey(0)
#applying filters
bil = cv2.bilateralFilter(img,50,30,30)
# cv2.imshow('res2'+img_name,bil)
# cv2.waitKey(0)
#applying filters
bil = cv2.bilateralFilter(bil,15,60,60)
# cv2.imshow('res2'+img_name,bil)
# cv2.waitKey(0)
#applying filters
median = cv2.medianBlur(bil,5)
# cv2.imshow('res2'+img_name,median)
# cv2.waitKey(0)
median = cv2.medianBlur(median,5)
# cv2.imshow('res2'+img_name,median)
# cv2.waitKey(0)
# convert to np.float32
Z = np.float32(Z)
# # img = cv2.imread(img_name)
# Z = median.reshape((-1,3))
# define criteria, number of clusters(K) and apply kmeans()
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)
K = 2
ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
# # convert to np.float32
# Z = np.float32(Z)
# # define criteria, number of clusters(K) and apply kmeans()
# criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)
# K = 12
# ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
# Now convert back into uint8, and make original image
center = np.uint8(center)
res = center[label.flatten()]
res2 = res.reshape((img.shape))
# # Now convert back into uint8, and make original image
# center = np.uint8(center)
# res = center[label.flatten()]
# res2 = res.reshape((img.shape))
cv2.imwrite(os.path.basename(img_name),res2)
cv2.imwrite(os.path.basename(img_name),median)
# cv2.imshow('res2'+img_name,res2)
# cv2.waitKey(0)
#cv2.imwrite('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/images/out/images_imdahl/kmean/'+img_name,res2)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
\ No newline at end of file
cv2.destroyAllWindows()
\ No newline at end of file
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