<jupyter_start><jupyter_text>Gerador de Imagens***  Importações<jupyter_code># pacote de procedimentos numéricos
import numpy as np
# pacote de morfologia matemática
import skimage.morphology as sk
# pacote de visualização gráfica
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Funções Auxiliares<jupyter_code>def element_generator(radius=4, state=True):
    ''''
    Gera um furo (elemento) do caractere em braille
    '''

    element = sk.disk(radius)

    if state == True:
        element[0, element.shape[1] // 2] = 0
        element[-1, element.shape[1] // 2] = 0
        element[element.shape[0] // 2, 0] = 0
        element[element.shape[0] // 2, -1] = 0
    else:
        element = np.zeros(element.shape, dtype='uint8')
    
    return element 
def zero_padding(image, width=1):
    '''
    Adiciona zeros na borda de um array
    '''

    image = np.pad(image, pad_width=width, mode='constant')

    return image 
def make_caractere(encoded_image, radius=4, pad_width=1):
    '''
    Gera uma imagem do caractere em braille
    '''
    
    caractere = [[np.concatenate((element_generator(radius, encoded_image[0][0]), 
                                  element_generator(radius, encoded_image[0][1])), axis=1)],
                 [np.concatenate((element_generator(radius, encoded_image[1][0]), 
                                  element_generator(radius, encoded_image[1][1])), axis=1)],
                 [np.concatenate((element_generator(radius, encoded_image[2][0]), 
                                  element_generator(radius, encoded_image[2][1])), axis=1)]]

    caractere = np.concatenate((np.squeeze(caractere[0]),np.squeeze(caractere[1]), np.squeeze(caractere[2])))

    caractere = zero_padding(caractere, width=pad_width)

    
    return caractere
def reshape_encoded_image(flatten):
    '''
    Cria uma array com o formato do gabarito de furos em braille
    '''

    encoded_image = np.array(flatten, dtype='uint8')
    encoded_image = encoded_image.reshape(3,2)
    

    return encoded_image
def caractere_generator(flatten_image, radius=4, pad_width=3):
    '''
    Gera um caractere em braille a partir de um array codificado
    '''

    encoded_image = reshape_encoded_image(flatten_image)
    caractere = make_caractere(encoded_image, radius, pad_width)


    return caractere<jupyter_output><empty_output><jupyter_text>Teste da Classe<jupyter_code>import caractere_generator_v_1_0 as gi
constructor = gi.caractere_gen_v_1_0()
plt.imshow(constructor.caractere_generator([1,0,1,0,1,0], radius=4, pad_width=3), cmap='gray')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11897475133894414, 'fraction_numerical': 0.02142310635042081, 'mean_word_length': 3.5557491289198606, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '606192', 'license': 'MIT', 'n_tokens_mistral': 908, 'n_tokens_neox': 887, 'n_words': 172, 'path': 'make-images/caractere-generator-train.ipynb', 'repo_name': 'code-coffee-ufcg/braillingo-backend', 'size': '2614'}