Last active
September 22, 2022 04:23
-
-
Save lydiang/a1c403fd5ad3f6bc687d0031cd24d86a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SimpleITK as sitk | |
import numpy as np | |
import pandas as pd | |
# downloaded from http://download.alleninstitute.org/informatics-archive/current-release/mouse_ccf/annotation/ccf_2017/ | |
filename = 'annotation_25.nrrd' | |
itkimage = sitk.ReadImage(filename) | |
print(itkimage) | |
numpyImage = sitk.GetArrayFromImage(itkimage) | |
values, counts = np.unique(numpyImage[:], return_counts=True) | |
df = pd.DataFrame() | |
for x in range(len(values)) : | |
rec = {} | |
rec['count'] = counts[x] | |
rec['value'] = values[x] | |
df = df.append(rec, ignore_index= True ) | |
df['value'] = df['value'].astype(np.int) | |
df['count'] = df['count'].astype(np.int) | |
filename = 'value_count.csv' | |
df.to_csv( filename, index=False ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Open annotation_25.nrrd file using SimpleITK and count the number of unique values