Skip to content

Instantly share code, notes, and snippets.

View ofgulban's full-sized avatar

Omer Faruk Gulban ofgulban

View GitHub Profile
@ofgulban
ofgulban / NII_to_FMR.m
Created October 31, 2019 13:56
Nifti to Brainvoyager's fmr file format conversion.
% Convert FMR to NII for files converted from FMR to NII before.
%
% Requires Neuroelf <http://neuroelf.net/>.
clc; clear all;
PATH_OUT = '/patt/to/output_folder';
SUFFIX = 'converted'
% set nii names created after spm or fsl manipulation
@ofgulban
ofgulban / FMR_to_NII.m
Last active October 31, 2019 13:56
Brainvoyager's fmr format to nifti conversion.
% Convert FMR to NII
%
% Requires Neuroelf <http://neuroelf.net/>.
clear all;
% Set path with nii files
PATH_OUT = '/patt/to/output_folder';
% Set fmr names
@ofgulban
ofgulban / volume_render_pyqtgraph.py
Last active June 6, 2021 04:25
Volume rendering of a nifti file using pyqtgraph library.
"""Test GL volume tool with MRI data."""
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import numpy as np
from nibabel import load
FILENAME = "/path/to/file.nii.gz"
RENDER_TYPE = "translucent"
THR_MIN = 100
@ofgulban
ofgulban / NII_to_VMR_orientation_fix.m
Last active October 3, 2018 16:23
This is an example script to change image orientation in Brainvoyager after using the Nifti plugin within Brainvoyager.
% Nifti to vmr Brainvoyager (2.8.4) conversion orientation fix.
% This scripts requires neuroelf.
%
% Use Brainvoyager nifti to vmr converter with default optionss then use
% this script to reorient the data.
clc; clear all; close all;
in_file = '/path/to/converted_nifti.vmr';
@ofgulban
ofgulban / fnirt_example.sh
Last active September 20, 2018 10:42
An example FSL-FNIRT bash script.
in='/path/to/image.nii.gz'
ref='/path/to/reference_image.nii.gz'
command="${FSLDIR}/bin/fnirt "
command+="--ref=$ref "
command+="--in=$in "
command+="--cout=${in%.nii*}_cout.nii "
command+="--iout=${in%.nii*}_iout "
command+="--fout=${in%.nii*}_fout "
command+="--subsamp=2,2,1,1 " # sub-sampling scheme [default 4,2,1,1]
@ofgulban
ofgulban / nii_extract_roi.py
Last active August 26, 2023 11:40
Extract a sub-volume of a nifti file.
"""Extract a smaller volume from a bigger volume.
NOTE: The affine matrix is not manipulated. Therefore, the extracted volume
cannot be positioned properly in the initial volume (e.g. in ITKSNAP).
"""
import os
import numpy as np
from nibabel import load, Nifti1Image, save
@ofgulban
ofgulban / SRF2SRF_vertexwise_distance.m
Created July 6, 2018 12:04
Surface to surface seach for mapping parts of one mesh onto other in BrainVoyager
% Compute vertex to veretx euclidean distance in two different meshes.
%
% Note: This script will become slower as the angle threshold and search
% window increase.
clear all;
% surface
srf_name_1 = '/path/to/mesh1.srf';
% vessel
@ofgulban
ofgulban / POI_borderize.m
Last active April 27, 2018 10:28
Convert filled-in patches (BrainVoyager POI files) to only borders. Useful for creating publication figures of inflated meshes.
clear all;
% Inputs
poi_file = '/path/to/file.poi';
srf_file = '/path/to/mesh.srf';
suffix = 'borders';
blackened_borders = true;
% Load files
poi = xff(poi_file);
@ofgulban
ofgulban / SRF_mask_with_POI.m
Created December 8, 2017 17:38
Mask BrainVoyager surface (.srf) and surface map (.smp) files based on mesh regions (.poi).
clear all;
srf_path ='/path/to/mesh.srf';
srf = xff(srf_path);
out = [srf_path(1:end-4), '_POIcut.srf'];
poi = xff('/path/ro/areas.poi');
poi_idx = 1;
% (optional) cut smp
@ofgulban
ofgulban / NII_to_FMR_orientation_fix.m
Last active April 28, 2020 17:15
Convert nifti to fmr and change the orientations.
% Convert nifti to fmr and change the orientations.
% This scripts requires neuroelf.
%
% NOTES
% -----
% If you are getting erro about `Dyn3DToFMR`:
% 1. Clone the recent neuroelf version from <https://github.com/neuroelf/neuroelf-matlab> (this is written on 2020/04/28).
% 2. Copy `hdr_Dyn3DToFMR.m` file from neuroelf/_todo/@xff/private/ directory and paste in into neuroelf/@xff/private/ directory.
% 3. Comment out the following line fmrc.FirstDataSourceFile = hdrs.F; because otherwise it produces an error.
% 4. Add this modified neuroelf's path to your MATLAB.