beacon_aug/external/textflow/effects.py
def _stack_layers(self, text_arr, bg_arr, min_char_h, layer_type_params=None, is_mix_bg=False):
        """
        stack effect layer to synthesize image with text
        :param text_arr: 2D maks, {0, 255}
        :param bg_arr: RGB image
        :param min_char_h: the minimum character height in pixel
        :param layer_type_params: dict
            'text'      : [feather (True/False), text color (RGB/None/'rand'), opacity (.75~1)]
            'border'    : [is_rand_color (True/False), color (RGB/None)]
            'shadow'    : [theta (float/None), shift (float/None), opacity (.75~1/None)]
            'background': color (RGB)
        :param is_mix_bg: bool, whether combine text and bg by poisson editing
        :return: RGB image with text
        """

        if layer_type_params is None:
            layer_type_params = dict()

        """ create text layer """
        if TextEffects._layer_order[0] in layer_type_params:
            layers = [self.layer_type_dict[TextEffects._layer_order[0]](
                text_arr, bg_arr, min_char_h, layer_type_params[TextEffects._layer_order[0]])]
        else:
            layers = [self.layer_type_dict[TextEffects._layer_order[0]](
                text_arr, bg_arr, min_char_h)]

        """ create other layers except the background layer"""
        for l in TextEffects._layer_order[1:-1]:
            if l in layer_type_params:
                layers.append(self.layer_type_dict[l](
                    layers[0], bg_arr, min_char_h, layer_type_params[l]))

        """ create background layer """
        if TextEffects._layer_order[-1] in layer_type_params:
            layers.append(self.layer_type_dict[TextEffects._layer_order[-1]](
                layers[0], bg_arr, min_char_h, layer_type_params[TextEffects._layer_order[-1]]))
        else:
            layers.append(self.layer_type_dict[TextEffects._layer_order[-1]](
                layers[0], bg_arr, min_char_h))

        """ stack all layers by alpha blending """
        img_merged = self._merge_down(layers)

        """ poisson image editing """
        if is_mix_bg:
            img_merged = blit_images(img_merged, bg_arr)

        return img_merged.astype(np.uint8)

        stack effect layer to synthesize image with text
        :param text_arr: 2D maks, {0, 255}
        :param bg_arr: RGB image
        :param min_char_h: the minimum character height in pixel
        :param layer_type_params: dict
            'text'      : [feather (True/False), text color (RGB/None/'rand'), opacity (.75~1)]
            'border'    : [is_rand_color (True/False), color (RGB/None)]
            'shadow'    : [theta (float/None), shift (float/None), opacity (.75~1/None)]
            'background': color (RGB)
        :param is_mix_bg: bool, whether combine text and bg by poisson editing
        :return: RGB image with text
        
stack effect layer to synthesize image with text
stack effect layer to synthesize image with text
def _stack_layers(self, text_arr, bg_arr, min_char_h, layer_type_params=None, is_mix_bg=False):
        if layer_type_params is None:
            layer_type_params = dict()
        if TextEffects._layer_order[0] in layer_type_params:
            layers = [self.layer_type_dict[TextEffects._layer_order[0]](
                text_arr, bg_arr, min_char_h, layer_type_params[TextEffects._layer_order[0]])]
        else:
            layers = [self.layer_type_dict[TextEffects._layer_order[0]](
                text_arr, bg_arr, min_char_h)]
        for l in TextEffects._layer_order[1:-1]:
            if l in layer_type_params:
                layers.append(self.layer_type_dict[l](
                    layers[0], bg_arr, min_char_h, layer_type_params[l]))
        if TextEffects._layer_order[-1] in layer_type_params:
            layers.append(self.layer_type_dict[TextEffects._layer_order[-1]](
                layers[0], bg_arr, min_char_h, layer_type_params[TextEffects._layer_order[-1]]))
        else:
            layers.append(self.layer_type_dict[TextEffects._layer_order[-1]](
                layers[0], bg_arr, min_char_h))
        img_merged = self._merge_down(layers)
        if is_mix_bg:
            img_merged = blit_images(img_merged, bg_arr)
        return img_merged.astype(np.uint8)
def _stack_layers ( self , text_arr , bg_arr , min_char_h , layer_type_params = None , is_mix_bg = False ) : if layer_type_params is None : layer_type_params = dict ( ) """ create text layer """ if TextEffects . _layer_order [ 0 ] in layer_type_params : layers = [ self . layer_type_dict [ TextEffects . _layer_order [ 0 ] ] ( text_arr , bg_arr , min_char_h , layer_type_params [ TextEffects . _layer_order [ 0 ] ] ) ] else : layers = [ self . layer_type_dict [ TextEffects . _layer_order [ 0 ] ] ( text_arr , bg_arr , min_char_h ) ] """ create other layers except the background layer""" for l in TextEffects . _layer_order [ 1 : - 1 ] : if l in layer_type_params : layers . append ( self . layer_type_dict [ l ] ( layers [ 0 ] , bg_arr , min_char_h , layer_type_params [ l ] ) ) """ create background layer """ if TextEffects . _layer_order [ - 1 ] in layer_type_params : layers . append ( self . layer_type_dict [ TextEffects . _layer_order [ - 1 ] ] ( layers [ 0 ] , bg_arr , min_char_h , layer_type_params [ TextEffects . _layer_order [ - 1 ] ] ) ) else : layers . append ( self . layer_type_dict [ TextEffects . _layer_order [ - 1 ] ] ( layers [ 0 ] , bg_arr , min_char_h ) ) """ stack all layers by alpha blending """ img_merged = self . _merge_down ( layers ) """ poisson image editing """ if is_mix_bg : img_merged = blit_images ( img_merged , bg_arr ) return img_merged . astype ( np . uint8 )
stack effect layer to synthesize image with text
stack effect layer to synthesize image with text
"""
        stack effect layer to synthesize image with text
        :param text_arr: 2D maks, {0, 255}
        :param bg_arr: RGB image
        :param min_char_h: the minimum character height in pixel
        :param layer_type_params: dict
            'text'      : [feather (True/False), text color (RGB/None/'rand'), opacity (.75~1)]
            'border'    : [is_rand_color (True/False), color (RGB/None)]
            'shadow'    : [theta (float/None), shift (float/None), opacity (.75~1/None)]
            'background': color (RGB)
        :param is_mix_bg: bool, whether combine text and bg by poisson editing
        :return: RGB image with text
        """ """ create text layer """ """ create other layers except the background layer""" """ create background layer """ """ stack all layers by alpha blending """ """ poisson image editing """
RGB image with text
RGB image with text
self
text_arr
None
bg_arr
None
min_char_h
the minimum character height in pixel
the minimum character height in pixel
layer_type_params
dict
'text'      : [feather (True/False), text color (RGB/None/'rand'), opacity (.75~1)]
'border'    : [is_rand_color (True/False), color (RGB/None)]
'shadow'    : [theta (float/None), shift (float/None), opacity (.75~1/None)]
'background': color (RGB)
dict ' text ' : [ feather ( True / False ) text color ( RGB / None / ' rand ' ) opacity ( . 75~1 ) ] ' border ' : [ is_rand_color ( True / False ) color ( RGB / None ) ] ' shadow ' : [ theta ( float / None ) shift ( float / None ) opacity ( . 75~1 / None ) ] ' background ' : color ( RGB )
is_mix_bg
bool, whether combine text and bg by poisson editing
bool whether combine text and bg by poisson editing