<jupyter_start><jupyter_text>annotate images for U-Net training<jupyter_code>import os
import numpy as np
import napari
from skimage.io import imsave
PATH = "/Users/arl/Downloads/images_to_annotate"
GT_PATH = os.path.join(PATH, "GT")
from daskoctopus import DaskOctopusLiteLoader
reader = DaskOctopusLiteLoader(
    PATH, 
    crop=(1200, 1600),
    remove_background=True,
)
brightfield = reader["brightfield"]
files = reader.files("brightfield")
viewer = napari.Viewer()
viewer.add_image(brightfield)
viewer.add_labels(np.zeros(brightfield.shape, dtype=np.uint64), name="ground_truth")

@viewer.bind_key('x')
def save_ground_truth(viewer):

    idx = viewer.dims.current_step[0]
    _, raw_fn = os.path.split(files[idx])
    fn = os.path.join(GT_PATH, f"GT_{raw_fn}")

    if not os.path.exists(GT_PATH):
        os.makedirs(GT_PATH)
    
    print(idx, fn)
    gt = viewer.layers["ground_truth"].data[idx, ...]
    imsave(fn, gt.astype(np.uint8))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13585291113381, 'fraction_numerical': 0.012257405515832482, 'mean_word_length': 5.012269938650307, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '275483', 'license': 'MIT', 'n_tokens_mistral': 388, 'n_tokens_neox': 366, 'n_words': 61, 'path': 'annotate.ipynb', 'repo_name': 'lowe-lab-ucl/simple-unet', 'size': '979'}