beacon_aug/external/textflow/effects.py
def sample_from_data(self, bg_arr, rand=True):
        """
        sample RGB color from the background image
        :param bg_arr: a RGB image
        :param rand: whether sample randomly around the mean color
        :returns: foreground RGB, background RGB
        """

        """ get background color mean """
        bg_arr = cv2.cvtColor(bg_arr, cv2.COLOR_RGB2LAB)
        bg_arr = np.reshape(bg_arr, (np.prod(bg_arr.shape[:2]), 3))
        bg_mean = np.mean(bg_arr, axis=0)

        """ get nearest color in the color model """
        norms = np.linalg.norm(self.colorsLAB - bg_mean[None, :], axis=1)
        # nn = np.random.choice(np.argsort(norms)[:3])  # choose a random color amongst the top 3 closest matches
        nn = np.argmin(norms)
        data_col = self.colorsRGB[np.mod(nn, self.n_color), :]
        if rand:
            col1 = self.sample_normal(data_col[:3], data_col[3:6])
            col2 = self.sample_normal(data_col[6:9], data_col[9:12])
        else:
            col1 = np.array(data_col[:3]).astype(np.uint8)
            col2 = np.array(data_col[6:9]).astype(np.uint8)

        """ set foreground and background colors """
        if nn < self.n_color:
            return col2, col1
        else:
            return col1, col2

        sample RGB color from the background image
        :param bg_arr: a RGB image
        :param rand: whether sample randomly around the mean color
        :returns: foreground RGB, background RGB
        
sample RGB color from the background image
sample RGB color from the background image
def sample_from_data(self, bg_arr, rand=True):
        bg_arr = cv2.cvtColor(bg_arr, cv2.COLOR_RGB2LAB)
        bg_arr = np.reshape(bg_arr, (np.prod(bg_arr.shape[:2]), 3))
        bg_mean = np.mean(bg_arr, axis=0)
        norms = np.linalg.norm(self.colorsLAB - bg_mean[None, :], axis=1)
        nn = np.argmin(norms)
        data_col = self.colorsRGB[np.mod(nn, self.n_color), :]
        if rand:
            col1 = self.sample_normal(data_col[:3], data_col[3:6])
            col2 = self.sample_normal(data_col[6:9], data_col[9:12])
        else:
            col1 = np.array(data_col[:3]).astype(np.uint8)
            col2 = np.array(data_col[6:9]).astype(np.uint8)
        if nn < self.n_color:
            return col2, col1
        else:
            return col1, col2
def sample_from_data ( self , bg_arr , rand = True ) : """ get background color mean """ bg_arr = cv2 . cvtColor ( bg_arr , cv2 . COLOR_RGB2LAB ) bg_arr = np . reshape ( bg_arr , ( np . prod ( bg_arr . shape [ : 2 ] ) , 3 ) ) bg_mean = np . mean ( bg_arr , axis = 0 ) """ get nearest color in the color model """ norms = np . linalg . norm ( self . colorsLAB - bg_mean [ None , : ] , axis = 1 ) nn = np . argmin ( norms ) data_col = self . colorsRGB [ np . mod ( nn , self . n_color ) , : ] if rand : col1 = self . sample_normal ( data_col [ : 3 ] , data_col [ 3 : 6 ] ) col2 = self . sample_normal ( data_col [ 6 : 9 ] , data_col [ 9 : 12 ] ) else : col1 = np . array ( data_col [ : 3 ] ) . astype ( np . uint8 ) col2 = np . array ( data_col [ 6 : 9 ] ) . astype ( np . uint8 ) """ set foreground and background colors """ if nn < self . n_color : return col2 , col1 else : return col1 , col2
sample RGB color from the background image
sample RGB color from the background image
"""
        sample RGB color from the background image
        :param bg_arr: a RGB image
        :param rand: whether sample randomly around the mean color
        :returns: foreground RGB, background RGB
        """ """ get background color mean """ """ get nearest color in the color model """ # nn = np.random.choice(np.argsort(norms)[:3])  # choose a random color amongst the top 3 closest matches """ set foreground and background colors """
foreground RGB, background RGB
foreground RGB background RGB
self
bg_arr
a RGB image
a RGB image
rand
whether sample randomly around the mean color
whether sample randomly around the mean color