<jupyter_start><jupyter_text>Pandas template* Cells before the ` [[nbplot]] template` are ignored.* Cells starting with ` [[nbplot]] ignore` are also ignored.* Some variables are substituted in every cell:    * `${root_path}`: the working directory when `nbplot` was called. Input files will be relative to this.* Some variables are subtituted in the `[[nbplot]] for i,input in enumerate(inputs)` blocks:    * `${i}`: index of the input in the list    * `${input.pretty_name}`: truncated path of the file, or 'stdin'    * `${input.rel_path}`: path of the file relative to the `root_path`, or `stdin`    * `${input.abs_path_or_io}`: full filepath or StringIO when the data comes from stdin    * `${input.guessed_sep}`: separator guessed by nbplot for this file. Usually space or comma.<jupyter_code># [[nbplot]] template
# Note: don't change that first line, it tells nbplot that the notebook below is a template
# This cell will be executed and the metadata dictionary loaded, but not included in the output.

template_metadata = {
    'name': 'daltonize',
    'format_version': '0.1'
}
import io, math, os, sys
from base64 import b64decode
from pathlib import Path
from IPython.core.display import HTML

import matplotlib.pyplot as plt
import numpy as np

import PIL

# Install daltonize if necessary
try:
    from daltonize import daltonize
except ImportError:
    !pip install -q daltonize
    from daltonize import daltonize

# Uncomment to get interactive plots.
# %matplotlib notebook

# Convert a float image to uint8 with proper clipping to 0,255
def image_to_uint8(im): return np.clip(im, 0., 255.).astype(np.uint8)

def process_image(name, abs_path_or_io):
    im = PIL.Image.open(abs_path_or_io).convert('RGB')

    plt.ioff();
    
    display(HTML('<hr>'))    
    fig,axs = plt.subplots(1, 3, figsize=(16,8), constrained_layout=True)
    fig.suptitle('Color Channels swap/invert', fontsize=24)    
    np_im = np.array(im)
    np_flip_red_blue = np_im[:,:,[2,1,0]]
    np_flip_green_blue = np_im[:,:,[0,2,1]]
    axs[0].imshow(im)
    axs[0].set_title(name)
    axs[1].imshow(np_flip_red_blue)
    axs[1].set_title('Flip Red/Blue')
    axs[2].imshow(np_flip_green_blue)
    axs[2].set_title('Flip Green/Blue')    
    plt.show()
            
    display(HTML('<hr>'))    
    fig,axs = plt.subplots(1, 3, figsize=(16,8), constrained_layout=True)
    fig.suptitle('Daltonize Enhancement', fontsize=24)
    axs[0].imshow(image_to_uint8(daltonize.daltonize(im, color_deficit='p')))
    axs[0].set_title('Protanope')
    axs[1].imshow(image_to_uint8(daltonize.daltonize(im, color_deficit='d')))
    axs[1].set_title('Deuteranope')
    axs[2].imshow(image_to_uint8(daltonize.daltonize(im, color_deficit='t')))
    axs[2].set_title('Tritanope')
    plt.show()

    display(HTML('<hr>'))
    fig,axs = plt.subplots(1, 3, figsize=(16,8), constrained_layout=True)
    fig.suptitle('Simulate Color Blindness', fontsize=24)
    axs[0].imshow(image_to_uint8(daltonize.simulate(im, color_deficit='p')))
    axs[0].set_title('Protanope')
    axs[1].imshow(image_to_uint8(daltonize.simulate(im, color_deficit='d')))
    axs[1].set_title('Deuteranope')
    axs[2].imshow(image_to_uint8(daltonize.simulate(im, color_deficit='t')))
    axs[2].set_title('Tritanope')
    plt.show()
    
    plt.ion(); # restore interactive mode
root_path = Path("$root_path")

# [[nbplot]] for i,input in enumerate(inputs)
process_image("${input.pretty_name}", ${input.abs_path_or_io})
# [[nbplot]] endfor<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14058053500284576, 'fraction_numerical': 0.01935116676152533, 'mean_word_length': 4.669354838709677, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '167826', 'license': 'MIT', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1269, 'n_words': 295, 'path': 'nbplot/templates/nbplot-daltonize.ipynb', 'repo_name': 'nburrus/nbplot', 'size': '3514'}