Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import matplotlib.image as mpimg
- import numpy as np
- def get_hue(bgr):
- #print bgr.shape
- max_val = max(bgr)
- min_val = min(bgr)
- if max_val == bgr[0]: # Blue is max val
- return 4.0 + (bgr[2] - bgr[1]) / (max_val - min_val)
- if max_val == bgr[1]: # Green is max val
- return 2.0 + (bgr[0] - bgr[2]) / (max_val - min_val)
- if max_val == bgr[2]: # Red is max val
- return 0.0 + (bgr[1] - bgr[2]) / (max_val - min_val)
- def bubble_sort_step(row):
- """row needs to have shape (x, 3)"""
- for i in range(1,row.shape[0]):
- if get_hue(row[i-1,:]) > get_hue(row[i,:]):
- temp = np.copy(row[i,:])
- row[i,:] = row[i-1,:]
- row[i-1,:] = temp
- #row[i-1], row[i] = row[i], row[i-1]
- return row
- plt.figure(figsize=(5,5))
- img = np.random.rand(100,100,3)
- for i in range(img.shape[1]):
- plt.imshow(img)
- for j in range(img.shape[0]):
- img[j,:,:] = bubble_sort_step(img[j,:,:])
- plt.pause(0.001)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement