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
"""Maximum intensity projection over one dimension for a window.""" | |
import os | |
import numpy as np | |
from nibabel import load, Nifti1Image, save | |
nii = load('/path/to/file.nii.gz') | |
w = 10 # window, total width is double of this number |
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
# Compile an MP4 from a folder containing PNGs | |
ffmpeg -y -i /path/to/movie_frame-%03d.png -vb 20M -c:v libx264 -vf fps=24 -pix_fmt yuv420p path/to/movie.mp4 | |
# Convert mp4 into a high quality gif | |
ffmpeg -y -i path/to/movie.mp4 -vf "fps=24, scale=768:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 path/to/movie.gif | |
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
"""Polish manually edited MRI white & gray matter segmentations.""" | |
import os | |
import nibabel as nb | |
import numpy as np | |
from scipy.ndimage import morphology, generate_binary_structure | |
from scipy.ndimage import gaussian_filter | |
# Segmentation file | |
FILE = '/path/to/segmentation_01.nii.gz' |
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
"""Simulate the spurious correlation of ratios. | |
Run this script multiple times and see the correlations between variables. | |
Reference | |
--------- | |
- Pearson, K. (1896). Mathematical Contributions to the Theory of Evolution. | |
On a Form of Spurious Correlation Which May Arise When Indices Are Used in the | |
Measurement of Organs. Proceedings of the Royal Society of London, 60, 489–498. | |
<https://doi.org/10.1098/rspl.1896.0076> |
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
"""Used for rendering frames as png files.""" | |
import sys | |
import os | |
import numpy as np | |
import pyvista as pv | |
import nibabel as nb | |
FILENAME = "/path/to/image3D.nii.gz" | |
OUTDIR = "/path/to/output" |
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
% Convert BrainVoyager reions of interests in volume (VOI) to .vmr files | |
% | |
% Similar to draw VOI in VMR option in BV but assigns unique numbers for | |
% each voi. | |
clear all | |
vmr_file = '/path/to/file.vmr'; | |
voi_file = '/path/to/file.voi'; |
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
"Make affine matrix of a nifti file identity matrix." | |
import os | |
import nibabel as nb | |
import numpy as np | |
NII = "/path/to/tile.nii.gz" | |
nii = nb.load(NII) | |
data = np.asarray(nii.dataobj) |
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
"""Compute volume of non-zero voxels in a nifti image.""" | |
import numpy as np | |
import nibabel as nb | |
INPUT = "/path/to/image.nii.gz" | |
# Load data | |
nii = nb.load(INPUT) | |
img = nii.get_fdata() |
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
"""Masked-ness score by source and derivative zero count ratio for images.""" | |
import numpy as np | |
import nibabel as nb | |
INPUT = "/path/to/image.nii.gz" | |
# ============================================================================= | |
def maskedness_score(img): |
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
% BrainVoyager SRF triangular mesh format to Wavefront OBJ format conversion. | |
%{ | |
Dependencies | |
------------ | |
1- Neuroelf should be added to Matlab path. Source: http://neuroelf.net/, | |
tested version: 1.0 | |
2- Resulting file can be loaded to e.g. Meshlab. | |
%} | |
clear all; |
NewerOlder