diff --git a/examples/iterate_animation.gif b/examples/iterate_animation.gif deleted file mode 100644 index 6a84265..0000000 Binary files a/examples/iterate_animation.gif and /dev/null differ diff --git a/examples/iterate_animation1.gif b/examples/iterate_animation1.gif new file mode 100644 index 0000000..8fc5467 Binary files /dev/null and b/examples/iterate_animation1.gif differ diff --git a/examples/iterate_animation2.gif b/examples/iterate_animation2.gif new file mode 100644 index 0000000..587a4cc Binary files /dev/null and b/examples/iterate_animation2.gif differ diff --git a/examples/rotate_animation.gif b/examples/rotate_animation.gif deleted file mode 100644 index 65ee6e3..0000000 Binary files a/examples/rotate_animation.gif and /dev/null differ diff --git a/examples/rotate_animation1.gif b/examples/rotate_animation1.gif new file mode 100644 index 0000000..5e78d98 Binary files /dev/null and b/examples/rotate_animation1.gif differ diff --git a/examples/rotate_animation2.gif b/examples/rotate_animation2.gif new file mode 100644 index 0000000..4f1f8bf Binary files /dev/null and b/examples/rotate_animation2.gif differ diff --git a/giffify.py b/giffify.py index 6779c34..e28ad2d 100644 --- a/giffify.py +++ b/giffify.py @@ -20,15 +20,17 @@ def reset(): def main(): reset() - img = cv2.imread('images/minimalist_landscape1.jpg') # change file here + img = cv2.imread('images/minimalist_landscape4.jpeg') # change file here resized_img = cv2.resize(img, (40, 40), interpolation=cv2.INTER_AREA) #resized_img = cv2.resize(img, (60, 80)) img_r, img_g, img_b = split_rgb(resized_img) flatten_img_r, flatten_img_g, flatten_img_b = list(map(flatten, [img_r, img_g, img_b])) pixels = np.stack([flatten_img_r, flatten_img_g, flatten_img_b], axis=1) - print(pixels.shape[0]) - kmeans_filenames = run_kmeans(pixels, 4) + # K-MEANS + k = 4 + print("Number of Pixels:", pixels.shape[0]) + kmeans_filenames = run_kmeans(pixels, k) # ITERATION ANIMATION iterate_animation_dir = 'figs/' diff --git a/kmeans_mpl.py b/kmeans_mpl.py index 342aa51..0d832d5 100644 --- a/kmeans_mpl.py +++ b/kmeans_mpl.py @@ -81,7 +81,6 @@ def plot_rgb(data, centroids, i, file_path, end = False): ax = fig.add_subplot(111, projection='3d') ax.set_title("Iteration: " + str(i)) - ax.xaxis.labelpad, ax.yaxis.labelpad, ax.zaxis.labelpad = 10, 10, 10 ax.title.set_position([0.85, 1]) ax.title.set_size(10) @@ -97,22 +96,20 @@ def plot_rgb(data, centroids, i, file_path, end = False): for r, g, b in centroids: ax.scatter3D(r, g, b, s=200, facecolor=(r/255, g/255, b/255), edgecolor="black", zorder=2) - fig.savefig(file_path, dpi=100) + fig.savefig(file_path, dpi=100, bbox='tight', pad_inches=0) return fig, ax def rotate(data, centroids, directory_name): fig = plt.figure(figsize=(8, 6)) ax = fig.add_subplot(111, projection='3d') - - ax.xaxis.labelpad, ax.yaxis.labelpad, ax.zaxis.labelpad = 10, 10, 10 - ax.title.set_position([0.85, 1]) - ax.title.set_size(10) ax.set_axis_off() ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) + plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0) + plt.margins(0, 0, 0) r, g, b = data[:, 0], data[:, 1], data[:, 2] point_opacity = 0.7 @@ -124,11 +121,9 @@ def rotate(data, centroids, directory_name): rotate_filenames = [] for angle in range(0, 360, 3): - ax.set_title("Iteration: Final") - ax.view_init(elev=30, azim=angle) cur_filename = "rotate_animation" + str(angle) + ".png" - fig.savefig(directory_name + cur_filename, dpi=100) + fig.savefig(directory_name + cur_filename, dpi=100, pad_inches=0) rotate_filenames.append(cur_filename) return rotate_filenames