<jupyter_start><jupyter_text>Apply some filters to an image<jupyter_code>blurred_im = get_src_im().filter(ImageFilter.BLUR)

print("\nblurred image created. result: ")
print(f'format: {blurred_im.format}, size: {blurred_im.size}, mode: {blurred_im.mode}')
# blurred_im.show()
sharpened_im = get_src_im().filter(ImageFilter.SHARPEN)

print("\nsharpened image created. result: ")
print(f'format: {sharpened_im.format}, size: {sharpened_im.size}, mode: {sharpened_im.mode}')
# sharpened_im.show()<jupyter_output>new src image created. result: 
format: JPEG, size: (1920, 1080), mode: RGB

sharpened image created. result: 
format: None, size: (1920, 1080), mode: RGB<jupyter_text>helper utils<jupyter_code># darken a band by pct, go no lower than 0. ie green down by 20%:
# g = darken_band(g, 0.2)
def darken_band(band, pct):
    assert 0 < pct and pct < 1
    
    new_band = int(band - (band * pct))
      
    if new_band < 0:
        new_band = 0
        
    return new_band<jupyter_output><empty_output><jupyter_text>Load PixelAccess<jupyter_code># im = sharpened_im
# im = blurred_im
im = get_src_im()
# im.show()

grid = im.load()
print('\nimage loaded')
print(f'grid type: {type(grid)}')

# upper left is 0,0
# get any pixel
print(grid[10,2])
print(grid[50,120])

# iterate over pixels and do something cool.
im_w = im.size[0]
im_h = im.size[1]
pct = 0.2
for i in range(im_w):
    for j in range(im_h):
        # pixel is at grid[i,j]
        r, g, b = grid[i, j]
        grid[i, j] = darken_band(b, pct), darken_band(g, pct), darken_band(r, pct)
# im.show()
# format will be determined from filename extension.
im.save(f"{dest_image_prefix}_yellow_20pct_dark.jpg")
im.save(f"{dest_image_prefix}_yellow_20pct_dark.png") 
# swapp all blue and red values.
for i in range(im_w):
    for j in range(im_h):
        # pixel is at grid[i,j]
        r, g, b = grid[i, j]
        grid[i, j] = b, g, r
# im.show()
# format will be determined from filename extension.
# im.save(f"{dest_image_prefix}_red.jpg")
# im.save(f"{dest_image_prefix}_red.png")
# darken all pixels a bit
pct = 0.6

for i in range(im_w):
    for j in range(im_h):
        # pixel is at grid[i,j]
        r, g, b = grid[i, j]
        r = darken_band(r, pct)
        g = darken_band(g, pct)
        b = darken_band(b, pct)
        grid[i, j] = r, g, b
im.show()
# format will be determined from filename extension.
# im.save(f"{dest_image_prefix}_green.jpg")
# im.save(f"{dest_image_prefix}_green.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1433146517213771, 'fraction_numerical': 0.018014411529223378, 'mean_word_length': 3.880859375, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '647652', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1036, 'n_tokens_neox': 986, 'n_words': 250, 'path': 'pics/edit_fc.ipynb', 'repo_name': 'kouritron/dpex', 'size': '2498'}