def calculate():
from sklearn.metrics import mean_squared_error
import os
if not os.path.exists('plots'):
os.makedirs('plots')
for k in xrange(2, 22):
cluster = KMeans(k, init='k-means++', random_state=241)
cluster.fit(X)
reduced_image = recreate_image(cluster.cluster_centers_, cluster.labels_, h, w, d)
mse = np.mean((image - reduced_image) ** 2)
psnr = 10 * np.log10(1.0 / mse)
plot(reduced_image, "plots/plot%d.png" % (k))
print "k: %d, mse: %.2f psnr: %.2f" % (k, mse, psnr)
if psnr > 20:
return k
评论列表
文章目录