<jupyter_start><jupyter_text>Hermann 格子を描画してみる<jupyter_code>import numpy as np
import scipy as sp
import matplotlib.pylab as plt
from PIL import Image
def HermannLattice(sqsize=30, padsize=4, ny=6, nx=6):
    '''
    Hermann 格子を２次元格子状に描画する
    ｓｑsize　は四角形ブロックの大きさ
    paddize は，通路の大きさ
    ny, nx はブロック数
    '''

    width = padsize + (sqsize+padsize) * nx
    height = padsize + (sqsize+padsize) * ny

    bg = 0
    fg = 1

    img = np.zeros((height, width)) + bg

    for yy in range(ny):
        top = padsize + yy * (sqsize+padsize)
        btm = top + sqsize
        for xx in range(nx):
            lft = padsize + xx * (sqsize+padsize)
            rgt = lft + sqsize
            img[top:btm, lft:rgt] = fg
    return img
img = HermannLattice()

plt.figure(figsize=(10, 10))
plt.imshow(img, cmap='gray_r', interpolation='None')
plt.axis('off')
plt.savefig('HermanC.png', transparent='True', bbox_inches='tight', pad_inches=0.0)
np.savez("Hermann.npz", hermann=img)
from PIL import Image

Image.open('HermanC.png').convert('L').save('Herman.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13585951940850277, 'fraction_numerical': 0.012939001848428836, 'mean_word_length': 3.332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '597123', 'license': 'MIT', 'n_tokens_mistral': 474, 'n_tokens_neox': 454, 'n_words': 93, 'path': 'Misc/HermannLattice.ipynb', 'repo_name': 'shouno/Vision2CNNsample', 'size': '1082'}