Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. def create_clustering_mask( em, image ):
  2.     '''
  3.    Create clustering mask
  4.    '''
  5.     rows, cols, _ = image.shape
  6.     samples       = convert_to_samples( image )
  7.     mask          = []
  8.     pixels_list   = [None for x in range(255255)] # smaller foot print than dict
  9.    
  10.     print (rows * cols)
  11.  
  12.     for index in range( rows * cols ):
  13.         sample = samples[index:index+1, :]
  14.  
  15.         # rather than using more expensive hash, we know that
  16.         # S and V ranges between 0 - 255, so by using this
  17.         # we could uniquely store values between 000000 to 255255
  18.         key = int(sample[0][0] * 1000 + sample[0][1])
  19.         cluster = pixels_list[key]
  20.  
  21.         # Cache miss
  22.         if cluster is None:
  23.             cluster, prob = em.predict( sample )
  24.             pixels_list[key] = cluster
  25.  
  26.         mask.append( cluster )
  27.    
  28.     return np.array( mask ).reshape( rows, cols, 1 ).astype( 'uint8' )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement