Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

createBinarySegments.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. function [GM_img_bin, WM_img_bin, CSF_img_bin] = createBinarySegments(gm_fn, wm_fn, csf_fn, threshold)
  2. % DESCRIPTION:
  3. % This function constructs 3D binary masks for GM, WM and CSF based on the
  4. % relative value of GM/WM/CSF tissue probability maps per voxel. It assumes
  5. % that the image filename parameters are for images that are in the same
  6. % space (i.e. they match in size, voxel by voxel). If a threshold is
  7. % specified (0<= threshold <=1), the images are first thresholded before
  8. % the binary masks are calculated. For no threshold, specify zero.
  9. %
  10. % INPUT:
  11. % gm_fn - filename of pre-real-time functional scan
  12. % wm_fn - filename of T1-weighted structural scan
  13. % csf_fn - filename of T1-weighted structural scan
  14. % threshold -
  15. %
  16. % OUTPUT:
  17. % GM_img_bin - structure with filenames and data
  18. % WM_img_bin - structure with filenames and data
  19. % CSF_img_bin - structure with filenames and data
  20. %__________________________________________________________________________
  21. % Copyright (C) 2018 Neu3CA.org
  22. % Written by Stephan Heunis
  23. GM_spm = spm_vol(gm_fn);
  24. WM_spm = spm_vol(wm_fn);
  25. CSF_spm = spm_vol(csf_fn);
  26. GM_img = spm_read_vols(GM_spm);
  27. WM_img = spm_read_vols(WM_spm);
  28. CSF_img = spm_read_vols(CSF_spm);
  29. if threshold ~= 0
  30. GM_img_thresh = GM_img;
  31. WM_img_thresh = WM_img;
  32. CSF_img_thresh = CSF_img;
  33. GM_img_thresh(GM_img < threshold) = 0;
  34. WM_img_thresh(WM_img < threshold) = 0;
  35. CSF_img_thresh(CSF_img < threshold) = 0;
  36. GM_img_bin = (GM_img_thresh >= WM_img_thresh) & (GM_img_thresh >= CSF_img_thresh) & (GM_img_thresh ~= 0);
  37. WM_img_bin = (WM_img_thresh > GM_img_thresh) & (WM_img_thresh >= CSF_img_thresh) & (WM_img_thresh ~= 0);
  38. CSF_img_bin = (CSF_img_thresh > GM_img_thresh) & (CSF_img_thresh > WM_img_thresh) & (CSF_img_thresh ~= 0);
  39. else
  40. GM_img_bin = (GM_img >= WM_img) & (GM_img >= CSF_img) & (GM_img ~= 0);
  41. WM_img_bin = (WM_img > GM_img) & (WM_img >= CSF_img) & (WM_img ~= 0);
  42. CSF_img_bin = (CSF_img > GM_img) & (CSF_img > WM_img) & (CSF_img ~= 0);
  43. end