<jupyter_start><jupyter_text>Results above have a lot in common with the right image below which is the stabilized image from the paper (Fig. 12):![fig12](../resources/figs/fig12.png)<jupyter_code>flat = y[16:112,16:112].flatten()
ax = plt.subplot(1, 1, 1)
ax.hist(flat, bins=list(np.arange(-1100, 500, 1)))
plt.title("histogram of original image")
plt.show()
print(f'min: {np.min(flat)}, mean: {np.mean(flat)}, max: {np.max(flat)}')


flat = y_stab_9.flatten() - 1030
ax = plt.subplot(1, 1, 1)
ax.hist(flat, bins=list(np.arange(-1100, 500, 1)))
plt.title("histogram of stabilized image with 9 components")
plt.show()
print(f'min: {np.min(flat)}, mean: {np.mean(flat)}, max: {np.max(flat)}')



flat = y_stab_5.flatten() - 1030
ax = plt.subplot(1, 1, 1)
ax.hist(flat, bins=list(np.arange(-1100, 500, 1)))
plt.title("histogram of stabilized image with 5 components")
plt.show()
print(f'min: {np.min(flat)}, mean: {np.mean(flat)}, max: {np.max(flat)}')<jupyter_output><empty_output><jupyter_text>Using 9 components for the whole image<jupyter_code>print(img.shape)
fig1, ax1 = plt.subplots(1)
ax1.imshow(img, cmap='gray')
rect = patches.Rectangle((16, 16),288,288,linewidth=1,edgecolor='r',facecolor='none')
ax1.add_patch(rect)
plt.show()
mu = np.array([-987, -810, -540, -370, -160, 0, 100, 240, 340])
def get_block_stabilized_img(y, mu):
    neigh = 32
    block = 96
    w = y.shape[0]
    h = y.shape[1]
    y_stab = np.empty((w-neigh, h-neigh))
    for i in range(int((w-neigh)/block)):
        for j in range(int((h-neigh)/block)):
            print(i,j)
            big_y = expand(small_img=y[i*block:(i+1)*block + neigh, j*block:(j+1)*block+neigh], neighborhood_size=neigh)
            big_y = big_y[int(neigh/2) * neigh:(block+int(neigh/2)) * neigh, int(neigh/2) * neigh:(block+int(neigh/2)) * neigh]
            big_y_stab = run_third_algorithm(big_y, mu, non_central=True, constant_c=10, neighborhood_size=neigh, max_iter=4, tol=0.01)
            ys = contract(big_img=big_y_stab, neighborhood_size=neigh)
            y_stab[i*block:(i+1)*block, j*block:(j+1)*block] = ys
    return y_stab
y = img
y_stab = get_block_stabilized_img(y, mu_9)
plt.imshow(y_stab, cmap='gray')
plt.show()
plt.imshow(y[16:304,16:304], cmap='gray')
plt.show()
flat = y_stab.flatten() - 1030
ax = plt.subplot(1, 1, 1)
ax.hist(flat, bins=list(np.arange(-1100, 500, 1)))
plt.title("stabilized")
plt.show()
print(f'min: {np.min(flat)}, mean: {np.mean(flat)}, max: {np.max(flat)}')
flat = y[16:304,16:304].flatten()
ax = plt.subplot(1, 1, 1)
ax.hist(flat, bins=list(np.arange(-1100, 500, 1)))
plt.title("original")
plt.show()
print(f'min: {np.min(flat)}, mean: {np.mean(flat)}, max: {np.max(flat)}')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.06273062730627306, 'mean_word_length': 4.984547461368654, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '130381', 'license': 'Apache-2.0', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1112, 'n_words': 217, 'path': 'notebooks/debug.ipynb', 'repo_name': 's-mostafa-a/non-central-gamma-for-ct-scans', 'size': '2710'}