def rank_order(image):
 flat_image = image.ravel()
 sort_order = flat_image.argsort().astype(np.uint32)
 flat_image = flat_image[sort_order]
 sort_rank = np.zeros_like(sort_order)
 is_different = (flat_image[:(-1)] != flat_image[1:])
 np.cumsum(is_different, out=sort_rank[1:])
 original_values = np.zeros(((sort_rank[(-1)] + 1),), image.dtype)
 original_values[0] = flat_image[0]
 original_values[1:] = flat_image[1:][is_different]
 int_image = np.zeros_like(sort_order)
 int_image[sort_order] = sort_rank
 return (int_image.reshape(image.shape), original_values)

def rank_order ( image ) : flat_image = image . ravel ( ) sort_order = flat_image . argsort ( ) . astype ( np . uint32 ) flat_image = flat_image [ sort_order ] sort_rank = np . zeros_like ( sort_order ) is_different = ( flat_image [ : ( - 1 ) ] != flat_image [ 1 : ] ) np . cumsum ( is_different , out = sort_rank [ 1 : ] ) original_values = np . zeros ( ( ( sort_rank [ ( - 1 ) ] + 1 ) , ) , image . dtype ) original_values [ 0 ] = flat_image [ 0 ] original_values [ 1 : ] = flat_image [ 1 : ] [ is_different ] int_image = np . zeros_like ( sort_order ) int_image [ sort_order ] = sort_rank return ( int_image . reshape ( image . shape ) , original_values )
return an image of the same shape where each pixel is the index of the pixel value in the ascending order of the unique values of image .