Skip to content

Instantly share code, notes, and snippets.

View ofgulban's full-sized avatar

Omer Faruk Gulban ofgulban

View GitHub Profile
@ofgulban
ofgulban / bv_fmr_preprocessing.js
Last active December 29, 2019 08:30
Brainvoyager batch fmr preprocessing scripting example.
// Brainvoyager batch script for functional MRI data (.fmr) preprocessing.
//
// For more information, check the scripting guide:
// http://support.brainvoyager.com/automation-aamp-development/46-writing-scripts/133-scripting-reference-guide.html
var bvqx = BrainVoyagerQX;
bvqx.PrintToLog("---");
//----------------------------------------------------------------
@ofgulban
ofgulban / bv_vtc_creation.js
Last active January 5, 2018 16:30
Brainvoyager batch .vtc creation example.
// Batch script for VTC creation.
// From native functional data space to an anatomical data to ACPC and to TAL
//
// For more information, check the scripting guide:
// http://support.brainvoyager.com/automation-aamp-development/46-writing-scripts/133-scripting-reference-guide.html
var bvqx = BrainVoyagerQX;
bvqx.PrintToLog("---");
//----------------------------------------------------------------
@ofgulban
ofgulban / pyqtgraph_with_nibabel.py
Created January 20, 2017 10:10
Basic volume visualization for nifti MRI data using pyqtgraph.
"""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
# get MRI data
nii = load('/path/to/your/file/T1w.nii.gz')
data = nii.get_data()
@ofgulban
ofgulban / dilate_erode_MRI_data.py
Last active June 1, 2023 23:03
Simple morphological operations on MRI data (nifti).
"""Dilation, erosion, opening, closing operations on binary nifti files."""
import os
import numpy as np
from scipy.ndimage import morphology
from nibabel import load, save, Nifti1Image
# Load data
nii = load('/path/to/your/file.nii.gz')
basename = nii.get_filename().split(os.extsep, 1)[0]
@ofgulban
ofgulban / connected_clusters.py
Last active October 28, 2020 16:55
Connected clusters thresholding for nifti data.
"""Connected clusters cluster size thresholding commandline interface."""
import os
import argparse
import numpy as np
from nibabel import load, save, Nifti1Image
from skimage.measure import label
parser = argparse.ArgumentParser()
@ofgulban
ofgulban / VMP_to_NII.m
Last active April 20, 2021 20:26
Convert Brainvoyager VMP files to nii using neuroelf.
% Convert Brainvoyager VMP files to nii using neuroelf.
% Select VMR
[vmr_fileName, vmr_pathName] = uigetfile('.vmr');
vmr = xff(fullfile(vmr_pathName, vmr_fileName));
% Select VMP
[vmp_fileName, vmp_pathName] = uigetfile('.vmp');
vmp = xff(fullfile(vmp_pathName, vmp_fileName));
map_index = 1; % change this is you have multiple maps in one vmp file
@ofgulban
ofgulban / V16_to_NII.m
Last active April 29, 2021 10:05
Convert Brainvoyager VMR or V16 files to nii using Neuroelf.
% Convert Brainvoyager VMR or V16 files to nii using Neuroelf (v1.1 rc2).
[fileName, pathName] = uigetfile('.v16');
vmr = xff(fullfile(pathName, fileName));
vmr.ExportNifti(fullfile(pathName, [fileName(1:end-4),'.nii']) );
disp('Done.')
@ofgulban
ofgulban / FMR_delete_volumes.m
Last active May 19, 2017 14:27
Delete unwanted volumes from Brainvoyager FMR files.
% Delete unwanted volumes from timeseries data (Brainvoyager, FMR format).
clear all;
% Enter FMR file path and volume indices to be erased
fmr_path = '/path/to/your/file.fmr';
vol_erase = [50:60, 100:103];
% Load FMR (headers) and STC (data)
fmr = xff(fmr_path);
data = fmr.Slice.STCData(:, :, :, :);
@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.
@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