<jupyter_start><jupyter_text>Import Packages<jupyter_code>import numpy as np
import SimpleITK as sitk
import matplotlib.pyplot as plt

from tureplicator.replicate import TumorReplicator
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Obtain Tumor and Mask Arrays<jupyter_code>tumor_filepath = "../tumor.nii"
mask_filepath = "../tumor_mask.nii"

tumor_arr = sitk.GetArrayFromImage(sitk.ReadImage(tumor_filepath))
mask_arr = sitk.GetArrayFromImage(sitk.ReadImage(mask_filepath))

chosen_channel = [i for i in range(len(mask_arr)) if mask_arr[i, :, :].max()==1] # there is only one channel with mask annotated
assert len(chosen_channel) == 1
chosen_channel = chosen_channel[0]

tumor = tumor_arr[chosen_channel, :, :]
mask = mask_arr[chosen_channel, :, :]
plt.imshow(tumor)
# plt.savefig("tumor.png")
plt.imshow(mask)
# plt.savefig("mask.png")<jupyter_output><empty_output><jupyter_text>Generate New Tumor<jupyter_code>r = TumorReplicator(tumor_box_size=50, skull_threshold=190, outer_erosion=50, inner_erosion=5,
                   spawn_tol=0.6, overlap_range=(0.4,0.5), dist_transform_mask_size=5, dist_transform_scalar=1.5,
                   seed=42)
result = r.generate(tumor, mask)
plt.imshow(result)
# plt.savefig("result.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12460815047021943, 'fraction_numerical': 0.017241379310344827, 'mean_word_length': 6.6467065868263475, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '98491', 'license': 'Apache-2.0', 'n_tokens_mistral': 516, 'n_tokens_neox': 477, 'n_words': 76, 'path': 'notebooks/example_notebook.ipynb', 'repo_name': 'nicholaslaw/tumor-replicator', 'size': '1276'}