<jupyter_start><jupyter_text>Region Based Analysis This notebook shows the usage of _BlobMetrics_ class to do region based cell count Package import<jupyter_code>from IPython.core.pylabtools import figsize
figsize(10, 10)

from tifffile import imread, imsave
import numpy as np
from src.BlobDetector import BlobDetector
from src.BlobMetrics import BlobMetrics
import json<jupyter_output><empty_output><jupyter_text>The first step would be to give the raw brain image to the _BlobDetector_ package to get the centroids<jupyter_code>raw_img_path = 'data/region/reg_raw.tiff'
detector = BlobDetector(raw_img_path, n_components=3)
centroids = detector.get_blob_centroids()<jupyter_output><empty_output><jupyter_text>Next we want to do the region based analysis. For this two files are needed* Registered atlast image of the brain which has the region numbers as its intensity value* Ontology JSON which has the region number to name mapping<jupyter_code>reg_img_path = 'data/region/reg_atlas.tiff'
ontology_json_path = 'data/region/ara_structure_ontology.json'

metrics = BlobMetrics([], centroids, 12)
id2name, region_stats = metrics.get_region_based_count(ontology_json_path, reg_img_path)
print(json.dumps(region_stats, indent=4, sort_keys=True))<jupyter_output>0%|          | 0/595 [00:00<?, ?it/s][A
Processing region 0:   0%|          | 0/595 [00:00<?, ?it/s][A
Processing region 0:   0%|          | 1/595 [00:00<02:02,  4.84it/s][A
Processing region 1:   0%|          | 1/595 [00:00<02:04,  4.79it/s][A
Processing region 2:   0%|          | 1/595 [00:00<02:39,  3.72it/s][A
Processing region 2:   1%|          | 3/595 [00:00<01:04,  9.16it/s][A
Processing region 6:   1%|          | 3/595 [00:00<01:04,  9.11it/s][A
Processing region 7:   1%|          | 3/595 [00:00<01:16,  7.76it/s][A
Processing region 7:   1%|          | 5/595 [00:00<00:52, 11.20it/s][A
Processing region 9:   1%|          | 5/595 [00:00<00:53, 11.13it/s][A
Processing region 10:   1%|          | 5/595 [00:00<00:59,  9.84it/s][A
Processing region 10:   1%|          | 7/595 [00:00<00:47, 12.30it/s][A
Processing region 12:   1%|          | 7/595 [00:00<00:47, 12.26it/s][A
Processing region 15:   1%|          | 7/595 [00:00<00:53, 10.94it/s][A
Processing region 15:   [...]<jupyter_text>The `region_stats` variable has the region name along with the number of cells in that region. Now let's visualize the results<jupyter_code>metrics.plot_region_based_count(region_stats)<jupyter_output><empty_output><jupyter_text>Analysis with region-based intensity sums Average intensity of a region gives a good proxy for the number cells in that region. Now we are going to compare the region-based intensity sums with the cell detection results. From the below plot we see that the cell count and intensity sum correlate with each other.<jupyter_code>region_intensities = detector.get_avg_intensity_by_region(reg_atlas_path='data/region/reg_atlas.tiff')
metrics.plot_intensity_mapping(region_intensities, 'data/region/reg_atlas.tiff', id2name)<jupyter_output>0%|          | 0/595 [00:00<?, ?it/s][A
Summing intensities of region 0:   0%|          | 0/595 [00:00<?, ?it/s][A
Summing intensities of region 0:   0%|          | 1/595 [00:05<50:15,  5.08s/it][A
Summing intensities of region 1:   0%|          | 1/595 [00:05<50:16,  5.08s/it][A
Summing intensities of region 2:   0%|          | 1/595 [00:05<51:01,  5.15s/it][A
Summing intensities of region 2:   1%|          | 3/595 [00:05<17:07,  1.74s/it][A
Summing intensities of region 6:   1%|          | 3/595 [00:05<17:07,  1.74s/it][A
Summing intensities of region 7:   1%|          | 3/595 [00:05<17:22,  1.76s/it][A
Summing intensities of region 7:   1%|          | 5/595 [00:05<10:31,  1.07s/it][A
Summing intensities of region 9:   1%|          | 5/595 [00:05<10:31,  1.07s/it][A
Summing intensities of region 10:   1%|          | 5/595 [00:05<10:37,  1.08s/it][A
Summing intensities of region 10:   1%|          | 7/595 [00:05<07:40,  1.28it/s][A
Summing intensities of region 12:   1%[...]
{'fraction_non_alphanumeric': 0.1313706086095992, 'fraction_numerical': 0.10836219693221177, 'mean_word_length': 3.7397420867526376, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 19, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '295685', 'license': 'Apache-2.0', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1496, 'n_words': 402, 'path': 'Region Based Analysis.ipynb', 'repo_name': 'NeuroDataDesign/lids-bloby', 'size': '4042'}