Skip to content

Commit

Permalink
Added more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
allengu01 committed Sep 27, 2020
1 parent e65d59c commit 08bdd60
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 12 deletions.
Binary file removed examples/iterate_animation.gif
Binary file not shown.
Binary file added examples/iterate_animation1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/iterate_animation2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed examples/rotate_animation.gif
Binary file not shown.
Binary file added examples/rotate_animation1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/rotate_animation2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions giffify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down
13 changes: 4 additions & 9 deletions kmeans_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 08bdd60

Please sign in to comment.