Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create_clustering_mask( em, image ):
- '''
- Create clustering mask
- '''
- rows, cols, _ = image.shape
- samples = convert_to_samples( image )
- mask = []
- pixels_list = [None for x in range(255255)] # smaller foot print than dict
- print (rows * cols)
- for index in range( rows * cols ):
- sample = samples[index:index+1, :]
- # rather than using more expensive hash, we know that
- # S and V ranges between 0 - 255, so by using this
- # we could uniquely store values between 000000 to 255255
- key = int(sample[0][0] * 1000 + sample[0][1])
- cluster = pixels_list[key]
- # Cache miss
- if cluster is None:
- cluster, prob = em.predict( sample )
- pixels_list[key] = cluster
- mask.append( cluster )
- return np.array( mask ).reshape( rows, cols, 1 ).astype( 'uint8' )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement