Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 530

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 611

Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 728

Strict Standards: Redefining already defined constructor for class wpdb in /www/htdocs/w00a4756/wp-includes/wp-db.php on line 306

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-includes/cache.php on line 103

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /www/htdocs/w00a4756/wp-includes/cache.php on line 425

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-includes/theme.php on line 623

Strict Standards: Redefining already defined constructor for class WP_Dependencies in /www/htdocs/w00a4756/wp-includes/class.wp-dependencies.php on line 15
SPM for programmers » Code
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Feed on Posts or Comments

Category ArchiveCode



Code Martin Pyka on 10 May 2012

Import Niftis to Blender

I have no time to update BrainBlend for newer versions of SPM and Blender. Therefore, here is a small routine that exports a Nifti image to the 8-Bit RAW format which can be used in Blender to visualize structural and functional images as 3d-voxel cloud.

function exportData(img, output, scaling)
vol = spm_vol(img);
data = spm_read_vols(vol);
data = uint8(data*scaling);
figure, imagesc(data(:,:,50))
fid = fopen(output, 'wb')
fwrite(fid, data, 'uint8')
fclose(fid)

Code Martin Pyka on 28 May 2010

Extent threshold

The “extent threshold” function deletes all clusters in a given contrast image that consist of less than k voxels. The corresponding matlab code can be found in spm_getSPM.m (line 674f). In case you would like to use this code manually for other imaging data, here is a matlab-function called extentThreshold that allows you to apply the extent threshold on a 3d volume of your choice.

The function can be used in the following way: if data is a 3d-matrix (of let’s say voxel values) and you want to display clusters with voxels that are greater than zero and with a cluster size of at least 20, write:

indices = find(data>0);
newdata = extentThreshold(data, indices, 20);

newdata includes only the elements of data that are greater than zero and that belong to a cluster with at least 20 other elements exceeding this threshold.

Code Martin Pyka on 18 May 2010

Display the frequency domain of a signal

SPM has a nice feature to plot the frequency domain of a signal. You can use it, for example, when you click on “Review” and - after you selected an SPM.mat file - on “Design” - “Explore” - “Session 1″ - Regressor. The corresponding function can be found in spm_fMRI_design_show.m in line 90ff.

To call this plot directly from the Matlab console e.g. in order to visualize the frequency domain of extracted VOIs, I copied the code into a separate m-file function, which looks like this:

function fft_gui(signal, rt, HPF)
gX = abs(fft(signal)).^2;
gX = gX*diag(1./sum(gX));
q = size(gX,1);
Hz = [0:(q - 1)]/(q*rt);
q = 2:fix(q/2);
plot(Hz(q),gX(q,:))
patch([0 1 1 0]/HPF,[0 0 1 1]*max(max(gX)),[1 1 1]*.9);
xlabel(’Frequency (Hz)’)
ylabel(’relative spectral density’)
title(['Frequency domain',sprintf('\n'), ' {\bf',num2str(HPF),'}', ...
' second High-pass filter'],’Interpreter’,'Tex’);
grid on
axis tight

To display the frequency domain of a signal, just call this function with the appropriate RT and high-pass filter value, e.g.:

signal = (sin((1:100)*0.8)+sin((1:100)*1.4) + sin((1:100)*2))';
fft_gui(signal, 3, 128)